mercredi 1 novembre 2017

checkbox validation in knockout based on array values

Please see following fiddle: http://ift.tt/2xLdLrY I want to highlight checkboxes of NJ and NY if none is selected and remove highlight if either of them selected.

<input type="text" data-bind="value: username, valueUpdate: 'afterkeydown', css:{'error':(!username.isValid() && showErrors())}" />
 <div data-bind="value:stateVal,valueUpdate:'click', css:{'error':
(!username.isValid() && showErrors())}">
   <input type="checkbox">
 </div>

<div data-bind="value:StateOptions.toValue(),valueUpdate: 'click', css:{'error':(!stateVal.isValid())}">
                <input type="checkbox" data-bind=" checked: StateOptions.NYChecked" /><label>NY</label>
                <input type="checkbox" data-bind="checked: StateOptions.NJChecked" /><label>NJ</label>
            </div>

 </div>
<br/>
 <button data-bind="click: submit">Submit</button>
 <div data-bind="visible: showErrors, text: errors" />

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire