knockout.js - how to show one validation icon for radiobuttons group -
i'm using knockoutjs , knockout validation plugin.
i show 1 validation icon radio group, after 'question 1' title. how can this?
<label>question 1:</label> <div> <!-- ko foreach: answers --> <div> <input type="radio" data-bind="attr: { value: id, id: id, name: 'answers' }, checked: $parent.selectedvalue" /> <label data-bind="text: text, attr: { for: id }"></label> </div> <!-- /ko --> </div>
there jsfiddle example
also second question - why validation icons displaying in example?
thanks!
you can put validation message on element using validationmessage binding handler:
this shows validation message:
<label>question 1: <span data-bind="validationmessage: selectedvalue"></span>
this example shows custom message template:
<label>question 1: <input style="display:none" data-bind="value:selectedvalue, validationoptions: {messagetemplate: 'icon'}" /> </label>
or more simply, if want use default messagetemplate:
<label>question 1: <input style="display:none" data-bind="value:selectedvalue" /> </label>
as second question, messagetemplate processed whether field valid or not. allows show validation message (say green chackmark) while field valid, , show validation error once becomes invalid.
you can use if
binding handler in conjunction field
variable control when message visible.
<script type="text/html" id="icon"> <span data-bind="if: field.ismodified() && !field.isvalid()">x<span> </script>
Comments
Post a Comment