jQuery-Mask-Plugin icon indicating copy to clipboard operation
jQuery-Mask-Plugin copied to clipboard

How to Integrate jQuery Mask Plugin with React.js?

Open igorescobar opened this issue 9 years ago • 7 comments

I've made a simple jsfiddle showing how to integrate jQuery Mask with React.js: https://jsfiddle.net/igorescobar/47ubm7az/

igorescobar avatar Dec 27 '16 11:12 igorescobar

not work fiidle

rinatsafin avatar Aug 13 '18 10:08 rinatsafin

@rinatsafin You can refer to my new example https://jsfiddle.net/nhduy88/20s9ubrv/

duynguyenhoang avatar Aug 28 '18 17:08 duynguyenhoang

Hello, to use with React, i need to install this plugin and jquery too ?

wemersonrv avatar Dec 30 '18 18:12 wemersonrv

Definitely yes, It is jQuery plugin.

duynguyenhoang avatar Jan 02 '19 03:01 duynguyenhoang

Yes, Need install and import jQuery as $ and need to import the code on top of the file, like this:

import $ from 'jquery';
import 'jquery-mask-plugin/dist/jquery.mask.min'; 

Theeennn... You can use it:

$('.dinheiro').mask('#.##0,00', {
      reverse: true,
      placeholder: '0,00'
    });

I am clarifying this because I didn't find anyone saying nothing. And just adding the script into header tag doesn't work.

LuizFellype avatar Apr 05 '20 12:04 LuizFellype

так же почему то не работает если прописать в input data-mask="..."

relaxdd avatar Apr 24 '22 17:04 relaxdd

  1. First you must install jquery-mask-plugin by your package manager:

NPM:

npm i jquery-mask-plugin

Bower:

bower install jquery-mask-plugin

Meteor:

meteor add igorescobar:jquery-mask-plugin

Composer:

composer require igorescobar/jquery-mask-plugin


  1. Then you will import jquery and jquery-mask-plugin in your component:
import $ from 'jquery';
import 'jquery-mask-plugin';

const Component = () => {
  $(() => {
    $('#date').mask('00/00/0000');
  });

  return (
    <form onSubmit = { e => e.preventDefault() }>
      <input
        type = 'text'
        id = 'date'
        placeholder = '00/00/0000'
      />
    </form>
  );
}

export default Component;

Alberto-Frigatto avatar Dec 22 '22 16:12 Alberto-Frigatto