Home » Jquery » javascript – JQuery Masked Input Does Not Working in Rails 6-Exceptionshub

javascript – JQuery Masked Input Does Not Working in Rails 6-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I am trying to use the JQuery Masked Input in my form on Rails 6. But it seems to me that the application.js in assets is not working, i am not sure. I installed the plugin through yarn with the command: yarn add jquery-mask-plugin. It was included in package.json as a dependency.

To setup, I went to app/assets/javascripts/application.js. This is the file:

//= require jquery
//= require jquery_ujs
//= require jquery-mask-plugin
//= require_tree .

$.jMaskGlobals.watchDataMask = true;

In app/javascript/packs/application.js I tried to import the JQuery and the plugin ass well:

require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("jquery")
import 'inputmask';

Now in my form, this is how I tried to use the plugin:

<%= form.text_field :cpf, class:'form-control', 'data-mask': '999.999.999-99' %>

As I said before, I am not sure, but I think the problem is the application.js file in assets, cause I wrote a console.log("test") command just to see if it is executing and nothing appeared at the web console when the server was running.

Can someone would help me?

How to&Answer: