javascript - Remove checked property through jquery .model value not updated in knockout js -
i used jquery remove checked property of checkbox.the ui value updated.however, model value not updated. same old value there in model. if manually check unchecked checkbox model value updated. have scenario 1 checkbox click other checkbox should unchecked.the required functionality done through below code. need updated value in model.
answerclick: function (data, event) { var element = event.target; $(element).parents('.primarycasemain').find("div#" + valuetohide).find('input[type=checkbox]:checked').removeattr('checked'); }
here html code
<input type="checkbox" data-bind="attr:{id: $data.id , qid: $parent.id , qref: $data.questionrefsetstrings , uid: $data.uid , rel: $data.mutuallyexclusive ? 'true' : 'false'} ,checked: $data.selected, click: $root.answerclick , if: $root.appendqrefquestion($data.questionrefsetstrings, $data.noappendrequiredqref)">
you should use knockout implemented kind of functionality instead of jquery.
in viewmodel implement 2 properties, call them checkbox1
, checkbox2
.
var self = this; //to have access in anonymous functions this.checkbox1 = ko.observable(true); this.checkbox2 = ko.observable(false);
then subscribe changes of each of observables , set value of other observable false
if set value true.
this.checkbox1.subscribe(function(newvalue){ if(newvalue){ self.checkbox2(false); } }); this.checkbox2.subscribe(function(newvalue){ if(newvalue){ self.checkbox1(false); } });
then use checked
binding bind properties checkboxes
.
<input type="checkbox" data-bind="checked: checkbox1" /> <input type="checkbox" data-bind="checked: checkbox2" />
Comments
Post a Comment