RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.39k stars 2.17k forks source link

i want to add negative sign automatically for a decimal input to a field with inputmask #2173

Open iarvindonGH opened 5 years ago

knoxcard commented 5 years ago

Cant you just do this?

$(selector).inputmask({ mask: "-999.99"})
knoxcard commented 5 years ago

Close ticket?

iarvindonGH commented 5 years ago

Hi @knoxcard , i forgot to describe the exact scenario. below are the criteria it should meet.

  1. We should only allow user to enter numbers, negative sign and decimal values(upto 2 places) in the field.
  2. Negative sign and decimal values to 2 decimal places should be added automatically when user enter any positive value ranging 1 to 10000.
  3. User should be also allowed to enter negative sign and values in decimal places if they want.

If I am using your code $(selector).inputmask({ mask: "-999.99"}), i am forced to enter 3 number values and values in decimal places upto 2 points else it is automatically feeling up with underscores.

I am using the below code as of now which is helping me to achieve the above functionalities but only one scenario is not working which is when i enter negative value, it should just allow me to enter and do not change the negative sign but currently it is being changed to positive sign.

` $pageObjects.amount.inputmask(
"decimal", { allowMinus:true, digits:2, enforceDigitsOnBlur:true, rightAlign: false, onBeforeMask: function (value, opts) { if (value >= 0) { value = '-' + value; }
return value; } });

` Please help me out here. thanks a lot in advance.

iarvindonGH commented 5 years ago

Can anyone help me out here?

iarvindonGH commented 5 years ago

@RobinHerbots , could you please help me out here....Thanks

RobinHerbots commented 5 years ago

Hi, I'm on holiday currently. After my holiday I will add an option to enforce a negative number.

Best regards, Robin

Op zo 11 aug. 2019 07:18 schreef iarvindonGH notifications@github.com:

@RobinHerbots https://github.com/RobinHerbots , could you please help me out here....Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/RobinHerbots/Inputmask/issues/2173?email_source=notifications&email_token=AACNX347EQWRN7DXBVZAR4TQD6OJFA5CNFSM4IKJAJSKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4A2HCQ#issuecomment-520201098, or mute the thread https://github.com/notifications/unsubscribe-auth/AACNX36HXAN5AGH37CO7BYDQD6OJFANCNFSM4IKJAJSA .