Question

I'm customizing a simple_form gem-enabled form for which I'd like the phone number field to have a datamask from http://jasny.github.com/bootstrap/javascript.html#inputmask

My original code is:

  <%= f.input :phone, :required => true, 
            :input_html => { :maxlength => 14} %>

What is the code required to pass something like into the f.input?

Using something like input_html and label_html doesn't seem to work.

Was it helpful?

Solution

in your form try this:

<%= f.input :phone, :required => true, 
            :input_html => { :maxlength => 14, :"data-mask" => "999-999-9999" } %>

Also, assuming you're running Rails 3.1+ and you have the jasny files in your vendor/assets/javascripts directory, be sure to include the bootstrap-inputmask file in app/assets/javascripts/application.js:

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-inputmask
//= require_tree .
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top