Possible to set error message for field with preEdit/preCreate?

Possible to set error message for field with preEdit/preCreate?

LesserDJHLesserDJH Posts: 7Questions: 4Answers: 2

Consider the following simple preEdit...

->on( 'preEdit', function ( $editor, &$values ) {
    $editor
        ->field( 'test_field1' )
        ->setValue('123');
} );

...is it also be possible for me to set an error (or at least a message) that would display for that field, when setting the value?

This question has an accepted answers - jump to answer

Answers

  • LesserDJHLesserDJH Posts: 7Questions: 4Answers: 2
    Answer ✓

    Found it! I was looking in the wrong part of the manual. Something like this works like a charm:

    ->on( 'preEdit', function ( $editor, &$values ) {
        $editor
            ->field( 'test_field1' )
            ->setValue('123')
            ->validator( function ( $val, $data, $field, $host ) {
                return 'Here is my test validation message.';
            } );
    } );
    
  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin

    Perfect - thanks for posting back.

    Allan

Sign In or Register to comment.