Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checked binding is not working with radio buttons #61

Open
grprakash opened this issue Jun 12, 2022 · 0 comments
Open

checked binding is not working with radio buttons #61

grprakash opened this issue Jun 12, 2022 · 0 comments

Comments

@grprakash
Copy link
Contributor

The checked binding works well for checkboxes, but doesn't support radio buttons. The values initialized is always true/false based on checked/not checked. Also when multiple radio buttons are place for the same field, it take the value of the last one.

Example code:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Knockout pre-rendered: textInit</title>
  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"></link>
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-debug.js"></script>
  <script src="https://rawgit.com/ErikSchierboom/knockout-pre-rendered/master/dist/knockout-pre-rendered.js" type="text/javascript"></script>
</head>
<body>
  <ul>
    <li>
      <label>London:</label>
      <input type="radio" data-bind="init, checked: city" name="city" value="London"/>
    </li>
    <li>
      <label>Chennai:</label>
      <input type="radio" data-bind="init, checked: city" name="city" value="Chennai" checked="checked" />
    </li>
    <li>
      <label>Boston:</label>
      <input type="radio" data-bind="init, checked: city"  name="city" value="Boston"/>
    </li>
    <li>
      <label>View model:</label>
      <pre data-bind="text: ko.toJSON(viewModel)"></pre>
    </li>
  </ul>
  <script>
      function ViewModel() {
        var self = this;

        self.city = ko.observable();

      }

      var viewModel = new ViewModel();
      ko.applyBindings(viewModel);
  </script>
</body>
</html>

JsBin link to reproduce the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant