Field error message from global editor validator

Field error message from global editor validator

Loren MaxwellLoren Maxwell Posts: 481Questions: 118Answers: 10

For a global validator, can I return the error message to a specific field?

    ->validator(function ($editor, $action, $data) {
    
        foreach ($data['data'] as $id => $d) {
                return "I don't like"; // <- Can I return for a specific field?
            }
        }
    
        return true;
    })

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 65,506Questions: 1Answers: 10,880 Site admin
    Answer ✓

    There isn't an API to do that - but I think it would be a good idea to add one - thanks for the suggestion.

    As a workaround for the moment, what you could do is directly add the field error to the output object - e.g.:

    $output = $editor->data();
    $fieldErrors = $output['fieldErrors'];
    
    $fieldErrors[] = [
        'name' =>"myField",
        'status' => "I don't like";
    ];
    
    return "Error";
    

    Note that at the moment you still need to return a global error message that will be shown, otherwise the server-side would continue processing the data.

    Allan

Sign In or Register to comment.