[Résolu] numeric fields with commas causing a problem
This support ticket is created Il y a 7 années et 7 mois. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have multiple forms on a page. When I try to enter a numeric value (1,000) with a comma, it creates errors across all forms. If the form is the only one on the page, then it just puts up a validation error "enter numeric data".
I was going to just strip commas from the data before posts, but now I realize that the automatic validation runs before the validation hook, so I can alter the data before it tries to validate.
So at this point I don't have a server side solution. Is there another way?
I'll have to use JS if not, to alter it before saving.
That doesn't work, because It has to happen before validation, and there isn't a "before_validation" hook.
The validation is what's causing the error, because it's returning a "enter numeric value" response, even though it doesn't create the error via javascript like the rest of the errors are.
I know it was mentioned that the " multiple forms on one page" had been corrected in the latest version of CRED, but I think there are still issues with it. Error messages show up in all forms with something like this.
For now I have implemented a javascript solution to format the number (without comma) after you leave the input field. It is working well. I would just also like to see the server side fixed for it.
Here's the jquery plugin I'm using if anyone else needs it. hidden link
The built-in validation runs before the validation hook, so I don't think this will work. It's validating the data before you can touch it (server side).
You are right. Numeric field do not allow comma as of now. Please allow me to check with our developers and I'll get in touch with you as soon as possible.
I got the confirmation that numeric filed will only allow numeric input that means no comma or point or other special characters allowed as input to this field type.
We need to keep in mind, that Numeric Field can be used in Views for sorting or filtering and due to that reason whatever we change, must also keep working fine in that case.
Ok, that's understandable, but the validation needs to catch it client side then.
If i put 1,00 it will throw a client side validation error saying "enter numeric".
But If i put 1,000 , it will not throw any error because it sees it as a legitimate number, until it's posted, and then the validation throws an error. If it would just catch it client side, then that would fix the issue.
I started using a jquery plugin to fix the issue. It formats the number to ####.## once the focus leaves the input field.
You mentioned that periods are not allowed either, but I have never had any problems with periods. I use these fields for currency input (ie $234.00), and so far the jquery plugin is working well to fix the issue.