Mask in Rails fields

2

I'm getting a theoretically simple thing, I'm looking for a date mask on my application.js :

//= require maskedinput
jQuery(function($){
$("‪#‎datadoacao‬").mask("99/99/9999");
});

In my partial form:

<%= f.text_field :data_doacao, id: 'datadoacao' %>

And I'm using gem 'maskedinput-rails' .

In my template I make the following call

So I imported the direct javascript into the application.html.erb

<%= javascript_include_tag 'application', 'maskedinput' %>

Does anyone know why it's not working?

Note: I added the maskedinput file to assests/javascript

    
asked by anonymous 27.07.2016 / 05:32

4 answers

1

So I imported the direct javascript into the application.html.erb

<%= javascript_include_tag 'application', 'maskedinput' %>

    
27.07.2016 / 18:49
1

As you already done require on your application.js , make sure you require also from JQuery

//= require maskedinput
//= require jquery
jQuery(function($){
   $("‪#‎datadoacao‬").mask("99/99/9999");
});

Your javascript_include_tag already contains it, so suffice:

<%= javascript_include_tag 'application' %>

If you're using Chrome, just press F12 and select the console tab.

If everything is OK, something like this should appear:

Ifyouhaveanyerrors,somethinglike:

I do not know if it was very basic, but you display some error message can help a lot in diagnosing the problem.

    
27.07.2016 / 19:31
1

Hello, what you can do is also check if the element is getting the id you entered, what I use is usually the following:

<%= f.text_field :data_doacao, input_html: {'id': 'idQueQuer'} %>

But inspect the element and check if it has the correct id.

    
02.08.2016 / 01:47
1

Oops, man, look at MEIOMASK, I like it, and I find it respectively simple ... I've downloaded this repository ( link ), the operation is more or less as below:

'z': /[a-z]/,
'Z': /[A-Z]/,
'a': /[a-zA-Z]/,
'*': /[0-9a-zA-Z]/,
'/': /[/]/,
'n': /[0-9]/,
'@': /[0-9a-zA-ZçÇáàãâéèêíìóòôõúùü]/

$('#datadoacao‬').setMask({mask: "nn/nn/nnnn"});

Hope it helps

    
01.10.2016 / 15:03