Can we have an action (create, edit ...) in field validation ?
Can we have an action (create, edit ...) in field validation ?
Hello,
I would like to know if it's possible to have a validator only on specific action at field level :
Here, there is never 'test' in my log, what is wrong ?
But with Global validator, it works fine.
// Fields Validator
->fields(
Field::inst( 'USERID' )
->validator(function ($editor, $action, $data){
if ($action === Editor::ACTION_EDIT){
error_log('test');
}
return true;
})
This question has an accepted answers - jump to answer
Answers
I found i think, it could be correct ?
Use the
preCreate
andpreEdit
events to add a validator to a field based on what action is being performed.Allan
thank you can you give me a sample please
Allan
Thanks you very much, finally i did this :
It seem to works fine in field now.
What's impact to put it to preCreate ? It's just a best practice ?
That will work as well.
preCreate
is how I've always done it, I think the resulting code is a little cleaner, but its up to youAllan
ok thanks you for your fast support you can close topic.