mercredi 13 mars 2019

Hi, I have a "null" validation message for a group of checkboxes on submit

I am using this library https://github.com/asimism/native-validations in a form validation, it's working fine but I have an error message in the checkboxes group validation when I try to submit the group of checkboxes empty it appears: "null"

this is the demo link: you have to click "submit" without clicking any field in order to see the "null" message https://www.cssscript.com/demo/custom-html5-form-validator-native-validations/

apparentely, there is an error in this function

function checkBoxGroupValidate(event) {
       //get all checked checkboxes for a group and if its null then mark it invalid or valid
       var totalChecked = event.target.parentNode.querySelector("input[name$='[]']:checked");
       if (totalChecked === null) {
           var errorMessage = '';
           if(event.target.dataset.requireError){
               errorMessage = event.target.dataset.requireError;
           }else if(event.target.parentNode.dataset.requireError){
               errorMessage = event.target.parentNode.dataset.requireError;
           }else {
               errorMessage = OptionGroupMessage;
           }
           event.target.parentNode.classList.remove(SuccessClass);
           event.target.parentNode.classList.add(ErrorClass);
           if (event.target.parentNode.querySelector(HelpBlockSelector) === null) {
               event.target.parentNode.insertAdjacentHTML("afterbegin", MessageTag.replace("{0}", errorMessage));
           }
       } else {
           event.target.parentNode.classList.remove(ErrorClass);
           event.target.parentNode.classList.add(SuccessClass);
           var spanError = event.target.parentNode.querySelector(HelpBlockSelector);
           if (spanError !== null) {
               event.target.parentNode.removeChild(spanError)
           }
       }
   }




Aucun commentaire:

Enregistrer un commentaire