jQuery Validator - How to validate against non-form items?

后端 未结 2 1147
暖寄归人
暖寄归人 2020-12-19 09:39

I have a form where a user can keep adding items to a list. When they go to submit this page, I want to validate that this list actually has items in it (not the individual

2条回答
  •  伪装坚强ぢ
    2020-12-19 10:29

    I've found a solution in the source code:

    return $( this.currentForm )
            .find( "input, select, textarea, [contenteditable]" )
    

    So jquery-validation takes only these types of elements.. I simply added the attribute "contenteditable" to the element I want to validate and added a custom validator.

    $.validator.addMethod("raty-required", function (value, element, regexpr) { return $(element).raty("score") >= 0; }, "Bitte Bewertung abgegeben");

提交回复
热议问题