Adding errors to form validation doesn't work?

后端 未结 4 1828
予麋鹿
予麋鹿 2021-01-21 11:47

According to the Semantic UI docs on form validation, I can add errors manually:

add errors(errors) | Adds errors to form, given an array errors

4条回答
  •  既然无缘
    2021-01-21 12:17

    To perform server-side validation via AJAX, use a custom rule:

    $myForm = $('.ui.form');
    var settings = {
        rules: {
            custom: function () {
                // Perform AJAX validation here
                return false;
            }
        }
    };
    var rules = {
        ajaxField: {
            identifier: 'ajaxField',
            rules: [{
                type: 'custom',
                prompt: 'Custom error!'
            }]
        }
    };
    $myForm.form(rules, settings);
    

    Here it is in action: http://jsbin.com/sufiwafe/1/edit

    For how to use callbacks and form validation in general, there is an important discussion on the Semantic-UI issues page on GitHub. The author mentions:

    ... the documentation was ambiguous but validation + settings is passed like $(".form').form(rules, settings);

提交回复
热议问题