mercredi 10 janvier 2018

.prob() does not change the checkbox status from inside each() loop

I'm working on a project where I want to check checkboxes based on matching a regEx Pattern. MY_JSFIDDLE

I come across a very strange behavior:

function checkRegEx() {
    $.each(myjson, function (i, v) {
        var feedname = this.name;
    var regExPat1 = document.getElementById('regExField').value;
    var regExPat = new RegExp(regExPat1, 'gi');
    var matched_bool = regExPat.test(feedname);
    //console.log(matched_bool==true);
    if(matched_bool==true) {
        $("#"+feedname).prop('checked',true);
      //$("#"+feedname).click(); // THIS WORKS STRANGELY
      console.log($("#"+feedname).prop('checked'));
        //console.log("eval TRUE #" + feedname)
    } else {
        $("#"+feedname).prop('checked', false);
        //console.log("eval FALSEE #" + feedname)
    };
  });
  document.getElementById("regExField").focus();
};

I can change and read out the status of the checkbox but it won't affect the GUI. When I use $("#"+feedname).click(); it works as I would expect. So I'm calling the ID right. I'm working on the latest Chrome. Strangely I found another jsfiddle. Here the prop method works for me. So it can't be a browser issue.

(im aware that jsfiddle uses jquery_edge, that is not the reason why it works there and not in mine- I tested different jquery versions in both jsfiddles)

Any advice. Can't see what I'm doing wrong here.




Aucun commentaire:

Enregistrer un commentaire