0

I am trying to build a form in Drupal 7, one of the fields needs to have an input mask. I found the plugin masked input it seems like what I am searching for . Only there is no documentation on how to implement it (I read about currency and this plugin, yet here it is only about getting it to work).

I am new to Drupal, but searching on forums I came up with the following code:

function report_expenses_form($form, &$form_submit) {
  libraries_get_path('maskedinput') . '/misc/ui/jquery.maskedinput-1.3.js';
...
     $form['cash_advance']['amount'] = array(
        '#title' => t('Cash Advance : '),
        '#type' => 'textfield',
        '#default_value' => t('$ 00,00'),
        '#required' => TRUE,
        '#mask' => '$?999.999.999,99',
      );
....

I installed the "Libraries" and "Masked Input" plugins in Drupal and flushed my caches.

I downloaded the jquery.maskedinput-1.3.js and put it in my {DRUPAL_HOME}/misc/ui/

any Ideas?

thank you in advance

Willem de Vries
  • 153
  • 1
  • 2
  • 9
  • Is your problem now solved by @kalabro's answer? Unfortunately, I don't think it will fix it as I have tried it myself and I still get the same problem. Please advise if it is solved and the exact steps you took to solve it. Thanks. – therobyouknow Sep 18 '12 at 12:37
  • @therobyyouknow Nope it didn't solve anything. I stop using the plugin. hope you find a solution. – Willem de Vries Sep 21 '12 at 15:46

4 Answers4

2

This gets a little confusing. Here is what you need to do:

  1. Download the file from here
  2. In your sites/all/libraries folder, create a folder called "masked_input"
  3. Upload the file to your sites/all/libraries/masked_input folder
  4. Rename the file to jquery.maskedinput-1.3.js or jquery.maskedinput-1.3.min.js so that your final path to the file is either {DRUPAL HOME}/sites/all/libraries/masked_input/jquery.maskedinput-1.3.js or {DRUPAL HOME}/sites/all/libraries/masked_input/jquery.maskedinput-1.3.min.js
  5. Now you can enable the module.
  6. Profit!

Note: This is a temporary workaround that does not require you to patch the module or change any code. The module needs to be fixed to address these issues as documented here

Note 2: After install, you might need to rename {DRUPAL HOME}/sites/all/libraries/masked_input to {DRUPAL HOME}/sites/all/libraries/maskedinput in order to get it load and work.

0

I downloaded the jquery.maskedinput-1.3.js and put it in my {DRUPAL_HOME}/misc/ui/

This is system Drupal path and you have no need to change it's contents.
In Drupal Libraries are external scripts that are stored in special Libraries folder. In your case in sites/all/libraries.
So file jquery.maskedinput-1.3.js should be in sites/all/libraries/maskedinput folder.

kalabro
  • 506
  • 1
  • 3
  • 17
  • Thank you for pointing this out. I made the suggested adjustment, yet this is a matter of Drupal customs and not a solution I guess... – Willem de Vries May 23 '12 at 16:05
  • @kalabro - have you checked your answer? i.e. That `jquery.maskedinput-1.3.js` (downloaded from `http://digitalbush.com/projects/masked-input-plugin/`) should go in `sites/all/libraries/maskedinput` ? I have tried this and still get the same problem as Willem de Vries. In fact I have tried the same file with different names in `sites/all/libraries/maskedinput` - I have tried `jquery.maskedinput.js` `jquery.maskedinput-1.3.js` `jquery.maskedinput-1.3.min.js` & tried it in different folder locations: `sites/all/libraries/masked_input` `sites/all/libraries/` AND `sites/all/libraries/maskedinput` – therobyouknow Sep 18 '12 at 12:31
0

The problem with the above code is the field type. It should be:

'#type' => 'masked_input', instead of '#type' => 'textfield',

The module documentation shows this, but I didn't notice it for two days.

4444
  • 3,541
  • 10
  • 32
  • 43
0

The Sean's method only worked for me with old version 1.3.1 of masked input, after 2 weeks and almost giving up:

https://github.com/digitalBush/jquery.maskedinput/releases

Download the package, extract it and then:

cp jquery.maskedinput-1.3.1/dist/jquery.maskedinput.js {DRUPAL HOME}/sites/all/libraries/masked_input/jquery.maskedinput.1-3.js
cp jquery.maskedinput-1.3.1/dist/jquery.maskedinput.min.js {DRUPAL HOME}/sites/all/libraries/masked_input/jquery.maskedinput.1-3.min.js

Make another copy, as maskedinput:

cd {DRUPAL HOME}/sites/all/libraries/
cp -a masked_input maskedinput

Install libraries module, install masked_input and that's. Now you can use it. Maybe masked_input needs some update for jquery library 1.4 compatibility, I'm not Jquery expert just a thought.

Community
  • 1
  • 1