Validate Unique if numeric, and not unique when value is "EXTRA"
Validate Unique if numeric, and not unique when value is "EXTRA"
ztevie
Posts: 101Questions: 23Answers: 5
Hi, here's a tough one for you:
I have a field which normally is numeric and must be unique when it is. But, on some occasions the user can create a record where the field value is set to "EXTRA".
Is it possible to validate:
1. Unique if it's a number.
2. If it's not a number the string must be exactly "EXTRA". But the value EXTRA needn't be unique.
I mean the Editor validation on the pphp side...
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You should create a custom validation method. Example in the docs.
https://editor.datatables.net/manual/php/validation
Yes, I know about the custom validators.
But to emulate Unique I need to do my own check against the database. I was thinking the Unique method is so convenient...
The best would be to use a custom validation where if the value is numeric, the unique validation steps in, and if not, the value must be EXTRA. But I don't think it's possible to nest validate methods within custom validation functions.
I think in this case would would indeed need to create a custom validator. You can chain validation, but they must all pass and the
unique
validation wouldn't pass for the "extra" case.Allan
I did a custom validation by calling an outside function. Here's how in case someone else need it in the future. The value can not be changed when Edit row, so I just need it on Create: