Custom INSERT and field validation
Custom INSERT and field validation

I try to replace the default behavior of dataTables Editor like this :
$data = Editor::inst( $DT, 'users', 'id' )
->fields(
Field::inst( 'email' )
->validator( Validate::email(
ValidateOptions::inst()
->allowEmpty( false )
->optional( false )
->message( 'Provide a valid email' )
))
)
->on( 'preCreate', function ( $editor, $values ) {
...
// here i place my custom code
...
return false; // cancel the default behavior of Editor
});
The problem is : the validation is not performed.
I would like to use the dataTables Editor validation functions and my custom code for record creation.
How can i do this ?
This discussion has been closed.
Replies
You more or less can't I'm afraid. If you are doing your own insert / update / delete, then don't use the Editor libraries at all.
You could pull in the validation classes if you wanted and use them, but the libraries aren't designed to operate the way you have it there (for example that doesn't just cancel Editor's insert, but it tells the client-side the insert didn't happen!).
Allan
Also worth noting that
preCreate
occurs before validation so that the event handler could potentially add validation if required.Allan
Thanks @allan ! I will write my own code for this situation