Standalone Bubble editing - On submitting edit, PHP code is running custom validator on other field
Standalone Bubble editing - On submitting edit, PHP code is running custom validator on other field
I am using the editor in standalone mode.
Everything works ok, but when I include a custom validator in any field as below, on submission the validator always seem to be run for that field even though I am editing a different field.
Field::inst( 'grid' )
->validator( Validate::notEmpty() )
->validator( function ( $val, $data, $field, $host ) {
return (validate_locator( $val )) ? true : 'Enter a 6 digit grid square. No hyphens. E.G QF56IF. 6 characters max';
})
->setFormatter( function ( $val, $data ) {
return strtoupper($val);
}),
This discussion has been closed.
Answers
Yes - the validator will always run, as that is the only way to enforce a field being required. What you need to do is allow the field to be valid if it is not set:
Allan
Thanks Allan,
That works.
Thank you so much.
Hilary