Home Forums ACF PRO Custom validation. Validation error message does not disapear


Custom validation. Validation error message does not disapear

  • I created a custom validation for one of my fields. The validation works 100%. Passes when correct and displays an error message when it does not pass the validation.

    The only problem is. If there are other fields that do not pass the validation, and you have corrected the field on your custom validation. The message will not disappear. It stays there until all fields are validated correctly and then it will submit.

    It looks like once the field with custom validation has been validated once it won’t get validated again until submit. So the message never disappears.

  • Did some more testing. Field gets validated again, but message does not dissapear. Looks like some javascript on the front end does not clear the error message.

  • Some more information. When making the field required in the field settings. Then the message will disappear after the first validation fails, but after you corrected it and it passes validation again, the error message will be cleared. But I don’t want all fields with custom validation to be required.

  • I think I narrowed it further down. I think it is somehow some javascript which does not remove the error message from a field with custom validation.

    If I added this in the beginning of my code in the validation function

    if (($key = array_search($input, $GLOBALS['acf_validation_errors'])) !== false) {

    The text in the message dissapears, but the red error bar still stays

  • I finally managed to solve this problem, with adding some javascript to the head. I added the following code in my functions.php

    function my_acf_admin_head()
    	<script type="text/javascript">
    $(document).on('submit', '#post', function(){
    add_action('acf/input/admin_head', 'my_acf_admin_head');

    On submitting the form it removes all classes with “acf-error-message”

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Custom validation. Validation error message does not disapear’ is closed to new replies.