formtastic_masked_input

MaskedInput (JS) for Formtastic

MIT License

Downloads
5.4K
Stars
3
Committers
1

h1. formtastic_masked_input

Sometimes you want to mask your fields like phones, zipcodes or something like that.

This plugin will do it for you if you are using formtastic.

Note: the javascript file depends on Prototype 1.6.1 and Rails uses Prototype version 1.6.0.3, just update your prototype.js

h2. Installation

h3. Plugin

h3. Gem

Add gem dependency to your environment.rb:

And generate the masked_input.js:

h2. Usage

Include prototype.js and masked_input.js into layout:

And update your form field:

h2. Masks

The available masks are made for Brazil:

  • phone: (99) 9999-9999
  • cpf: 999.999.999-99
  • cnpj: 99.999.999/9999-99
  • date: 99/99/9999
  • cep: 99999-999
  • time: 99:99

If you want to add a custom mask, you can edit masked_input.js around line 301 (preferred) or add directly into your layout:

h2. Credits

Special thanks to "Justin French":http://github.com/justinfrench for "formtastic":http://github.com/justinfrench/formtastic and "Bjarte K. Vebjørnsen":http://github.com/bjartekv for "MaskedInput port for Prototype":http://github.com/bjartekv/MaskedInput.

h2. TODO

  • Make tests for plugin
  • Make tests for MaskedInput

Copyright (c) 2010 Gabriel Sobrinho, released under the MIT license