Knockout radio button check binding

I have ViewModel in which I have array of "Answers". "Answer" is object that has property 'Selected'. In my demo array I have two Answers. For first Selected=1 and for second Selected=0. I have no idea why both radio buttons are selected. Here is my demo link - and my binding is

<input type="radio" data-bind=" value: Selected, checked: Selected">

-------------Problems Reply------------


For radio buttons, KO will set the element to be checked if and only if the parameter value equals the radio button node’s value attribute or the value specified by the checkedValue parameter.

You should consider adding a selectedAnswerID property to your view model.

<!-- ko foreach: answers -->
<input type="radio" data-bind="value: answerID, checked: $parent.selectedAnswerID">
<!-- /ko -->

If you really want to keep the answer's selected state a part of the answer, then you can used the checkedValue part of the binding. Note that you won't have a way to "deselect" an answer unless you provide some sort of "clear" button because radio buttons aren't really intended to support multi-select.

<!-- ko foreach: answers -->
<input type="radio" data-bind="checked: selected, checkedValue: 1">
<!-- /ko -->

Category:knockout.js Views:0 Time:2018-03-12

Related post

  • WPF radio buttons - MVVM - binding seems to die? 2010-09-20

    I've bound the DataContext of the following Window to the code behind to give me a MVVM style to demonstrate this behaviour: <Window x:Class="WpfApplication1.Window1" xmlns="" xmlns:x="http:

  • How do I set previously selected radio button checked in classic asp after page is postbacked? 2010-06-09

    I have never worked on classic ASP and unfortunately I am supposed to modify an old classic ASP web site. ASP.Net ViewState does take care of maintaining control's state automatically. How do I do it in classic ASP? I have two radio buttons and a tex

  • Jquery radio button check 2010-06-17

    I want to check is there any radio button selected and if there is no selection to print some alert message. The html code is: <form action="" id="form" name="form" method="post"> <input type="radio" id="form_rd" name="form_rd" value="1">

  • Radio button checked property 2010-10-20

    How can I know if the radio button checked property is true in PHP, can anyone give me an example? Thanks.. --------------Solutions------------- You can try to ask for the checked attribute, see the example: <label for="public0"><input type=

  • Rails - How to make a conditional Radio Button checked? 2011-01-16

    Given a radio button like so: <%= radio_button_tag 'permission[role_id]', '2' %> How can I make the radio buttons checked status condition. To only be checked if @permission.role_id.nil? or if @permission.role_id == 2? I tried: <%= radio_but

  • How to uncheck all checkboxes with a single radio button checking property using jQuery 2011-06-23

    I have a requirement to uncheck all checkboxes with single radio button. My HTML Code is <table> <tr><td><input type="checkbox"></td><td><input type="checkbox"></td><td><input type="checkbox"

  • jquery- how to obtain the text shown on screen in a radio button/check box/list/drop down 2011-11-07

    I am working to parse a form and obtain the values of all elements, including the text boxes, radio buttons, check boxes, list boxes and drop down boxes. I am currently able to obtain the values for all of the above... By values I mean the value as a

  • Radio Buttons, Check boxes not lined up vertically with labels (Rails 3) 2012-04-01

    I've been looking for an existing answer to this question, but haven't found one. I am currently working on a Rails 3 project with some forms that have multiple choice/multiple selection questions with radio buttons and check boxes, respectively. I u

  • Check and radio button not binding in Knockoutjs 2011-08-18

    I have a function wich build html controls dynamic with jquery and Knockout, but check and radio button doesn't work , not binding Please check my code and tell me some answer. function createControls(id, ctrl) { var obj = $.parseJSON(ctrl.settings)[

  • jquery radio button checked attribute? 2009-10-06

    <input type="radio" value="G;-;P063P081719;-;84.063" name="awardDetail"/> <input type="radio" value="G;-;P063P091719;-;84.063" name="awardDetail"/> <input type="radio" value="G;-;P063Q081719;-;84.063" name="awardDetail"/> I am not s

  • extract html table information based on radio button checked 2009-11-28

    Using the example below, what combination of selectors could I use to get the text that contains "price"? (Assume user has clicked a radio button and the Submit button) <table border="1" id="modal_table"> <tbody> <tr> <td>

  • Mootools set radio button checked 2010-04-06

    I have 2 radio buttons and I used mootool while loading as window.addEvent('domready', function() { var chk="1"; if(chk==1){ $('edit-gender-0').set('checked',true); } else if(chk==2){ $('edit-gender-1').set('checked',true); } but it is not working at

  • Set radio button 'checked' in jquery based on ID 2010-06-25

    I have two radio buttons with the same name, one is checked by default. How can you check or uncheck a radio button in jQuery when selecting from id? I've tried: $('#radio1').attr('checked','checked'); $('#radio1').attr('checked', true); Nothing seem

  • Radio button check in iframe 2010-07-27

    I have javascript, which is in iframe. When i check radio button in iframe, on parent window change value. It working perfect on firefox, but not on IE... Can someone help me with this problem? <script type="text/javascript"> function getChecke

  • Radio Buttons "Checked" Attribute Not Working 2010-08-31

    <label>Do you want to accept American Express?</label> Yes<input id="amex" style="width: 20px;" type='radio' name='Contact0_AmericanExpress' value='1'/> No<input style="width: 20px;" type='radio' name='Contact0_AmericanExpress' c

  • If radio button checked add new form element using dom? 2010-09-17

    How do I use DOM in Javascript to check if a radio button is checked and then if so add new form elements to datesettings? //Radio buttons <input type="radio" id="dateoption" name="dateoption" value="1"> <input type="radio" id="dateoption" n

  • Radio button checked status with jQuery 2010-10-22

    Here is the basic code <ul> <li> <input type="radio" name="r" value="a" id="a" checked="checked" /> <label for="a">A</label> </li> <li> <input type="radio" name="r" value="b" id="b" /> <label for="b"

  • Radio Buttons & Check Boxes 2010-12-22

    Possible Duplicate: adding radio buttons and check boxes Can someone please help me to add radio buttons for the flavors and check boxes for the toppings? Please, any help will be greatly appreciated. I added some code but this isn't working import j

  • to find the value of the radio button checked 2011-02-21

    hi I have a radio button list inside a repeater , the repeater is inside a Datalist.i need to get the value of the selected radio button. Also I need to select only a single radio in entire datalist using javascript. --------------Solutions----------

  • Jquery Radio Button Checked, Whole Page quickly flicks 2011-03-01

    I have a form that has a question which has two radio options (Yes and No). I managed to get the code working fine, but when i click yes out of the radio button the whole screen flashes very quickly. I have never seen this before. can anyone help? $(

  • Magento Custom Options - make every first radio button checked 2011-03-15

    We have a Magento Shop with some products that have custom options as radio buttons. Every non required option has the first button checked by default but not the required ones. How can I make them checked? I've allready installed the extension Depen

  • Radio button checked with Html.RadioButtonFor 2011-04-21

    <%= Html.RadioButtonFor(m => m.AmortizationTermInYears, true, new { propertyName = "AmortizationTermInYears", onchange = "showAmortizationTermInYears();UpdateField(this);", amortizationTermInYearsRadio = "true" })%> How do I tell this helper

  • Prevent radio button check and show an alert 2011-05-14

    I'm trying to show an alert if a certain radio button in a group is checked and then to check the previously checked radio button again. I was thinking of two solutions: Adding a disabled attribute, but click events are then not fired so I can't pop

  • Check if all radio buttons checked having particular value 2011-05-20

    <input type="radio" checked="checked" value="true" name="child"> <span class="label">Show</span> <input type="radio" class="hide" value="false" name="child"> <span class="label">Hide</span> and another radio button

Copyright (C), All Rights Reserved.

processed in 0.077 (s). 11 q(s)