Reputation: 5178
I am using the jquery-inputmask-rails gem. Ultimately: it is pulling in Robin Herbots' inputmask jQuery plugin.
As instructed in the jquery-inputmask-rails
gem, I put this in application.js
:
//= require jquery.inputmask
//= require jquery.inputmask.extensions
//= require jquery.inputmask.numeric.extensions
And here are my two masks:
$(document).on('turbolinks:load', function() {
$('.mask_phone').inputmask({mask: "(999) 999-9999"});
$('.mask_money').inputmask({alias: 'currency', rightAlign: true, placeholder: "", prefix: '', autoGroup: false, digitsOptional: true});
});
As far as usage goes: you should be able to just add the appropriate masking class to the input:
<%= f.text_field :some_field, class: "mask_money" %>
The issue I am having is that the mask_phone
mask works, but the mask_money
does not work at all.
I do notice in the logs it says this:
TypeError: null is not an object (evaluating 'e.mask.toString')
The odd thing is that in another project: I did not use the jquery-inputmask-rail gem, but instead brought in the jQuery input mask code into the Vendor directory directly, and it worked.
What am I missing?
Upvotes: 0
Views: 1891
Reputation: 8025
In my case i forgot to execute/call
initializeMasks();
so dont forget to add this as script
block in the view or in the app/views/model/submodel/action.js.erb
file instead of using <scrip>
right in the view
after that i was able to define and see my input
field to work just fine using something similiar to this
<%= f.input :ein, input_html: { data: { mask: '00-0000000' } } %>
as you can see my mask is not complex just two digits then a dash and then other 7 digits but i hope this helps!
Upvotes: 0
Reputation: 5178
My gut tells me that the jquery-inputmask-rails gem is not looking at an updated version of Robin Herbots' input mask plugin.
vender
folder. application.js
I put //= require jquery.inputmask.bundle.js
and removed the require statements associated to the gem.And then all my input masks worked.
Upvotes: 1