0

Using can 2.2 : I'm having trouble getting a radio input field to be checked by default when also using the can-value attribute.

The relevant part of the stache template looks like this:

<input type="radio" name="visibility" value="corporate" can-value="reportData.visibility" checked="checked"/>

The relevant part of my viewModel looks like this:

can.Map.extend({
    reportData = {
        visibility: 'corporate',    
    }
});

I want the input value to be live-bound to my view model. According to the can 2.2 docs, I can use the can-value attribute on an input to reference a property on my view model and keep it in sync with the value of the input's value. My problem is the checked="checked" doesn't result in the input being checked by default, though the value on the input item (corporate) is being correctly live-bound. If I remove the can-value attribute, the check appears by default. How can I get both live-binding and a checked input by default with the help of can-value?

stark
  • 2,246
  • 2
  • 23
  • 35
foundling
  • 1,695
  • 1
  • 16
  • 22
  • Can you try can 2.3 - a lot of improvements were made in that release - and most of the regressions have been fixed. If you can't upgrade, I will need you to create a fiddle showing the error- I can create a starter fiddle for you. – Ryan Wheale Feb 06 '16 at 06:09
  • Unfortunately I'm bound to canjs 2.2. However I was able to get the checked feature to work by surrounding the checked attribute in a conditional helper, i.e. {{#is reportData.visibility 'corporate'}}checked{{/is}} . Not ideal, but it works. – foundling Feb 14 '16 at 20:35

0 Answers0