How to validate after preCreate?
How to validate after preCreate?
arvidsson.andreas@gmail.com
Posts: 3Questions: 2Answers: 0
Hi,
At creation I want my users to pick a word that will be part of a url. When they have choosen a word I add the rest ("https://myexample.com/") of the url by using a server side preCreate function. After that I would like to validate the url. But my code right now only validates the single word written by the user, and not the whole url created with my function. Any suggestions how to validate after, not before I set my new value?
->on( 'preCreate', function ( $editor, $values ) {
$editor
->field( 'link' )
->setValue("https://myexample.com/".$word)
->validator( 'Validate::url', array(
'message' => 'Not a url'
));
} )
This discussion has been closed.
Answers
Right - the validator runs on the raw data submitted by the end user (before the formatter is applied, which is what
setValue
ends up being here).The result is that in this case you'd need to effectively format it twice. Perhaps moving it into its own function would help keep the code DRY.
Allan