The required validation for number inputs in JSON format fails required validators as it expects form data, other validations however work fine.
Is there any way to make the required validator support JSON?
The required validation for number inputs in JSON format fails required validators as it expects form data, other validations however work fine.
Is there any way to make the required validator support JSON?
I think this is a bug. @patrick?
Not really a bug but probably should require an update. The validator rules was for validating form data which is always strings, it just can’t handle other data than strings. I’ve checked the required rule and it checked if the value is set and if the length is larger than 0. This will check empty string and empty array which is data that it expects. Most validators will check if the input is a valid string or return false if not.
So the length check is failing here?
I have seen such validation fail once/twice. Don’t remember any case recently… but there is a fix needed for numeric values.
Yes looks that way as @patrick explained.
So the workaround for this is to add a validate step with {{$_POST.number.toString()}}
And add required for that. However it would be great if the fix was implemented for this.
The validation rules are an exact copy of the client-side form validation. All rules are based on strings, the number/integer validator checks the value with a regexp and will fail on real numbers/integers. This is because an (number) input value always returns a string, also when posting to the server or getting values from the querystring, all values are strings. Changing them will make them behave different than the same validator client-side, but we should probably do that to correctly support json data validation.