DynamicForm reinitialize maskedinput

I’m having an issue after inserting a new row in the dynamicform in which the submitted values no longer remove the , at submission thus causing an SQL exception.

$( "[data-plugin-inputmask]" ).each(function() {
        "digitsOptional": false,

I have tried all sort of variations of code (above is my latest attempt) to reinitialize the inputs, but just can’t get it right. They behave properly, but upon submission the do not remove the mask as they should. If I open an existing record, and make an entry such as 1300, it works fine, submits, saves. If I open that same record, make the entry 1300 and add a new record to the dynamic form, it won’t save and I can see in the error log that a value of 1,300.00 was being pushed rather than 1300.00.

Could someone offer any guidance.

I’ve put in place a workaround, use the model beforeSave to str_replace comma for the field.

I’d still love to learn if their is another, better solution to this though?

Data formatting is a bigger problem then it looks, are you using an extension for it or using the JS plugin directly?
My suggestion is to use one existing Yii2 extension, they usually solve this JS integrations problems to work with Yii2.

Now, about your problem, if you are saving numbers as currency in your model, they will be saved as decimal(19.4) (or some similar datatype) in a the database.
But, the model may work with this number as a number OR as string!

When you submit data from front-end, you are probably sending the formatted version of this currency string, which yields ‘1,300.00’, this way the model in the back-end will receive and work with a string. Which will lead to your error.

My suggestion is to perform a conversion in the rules(), where you could “correct” these data upon model validation.

1 Like