# Checkbox inputs and value attributes

**URL:** <https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254>\
**Category:** Uncategorized\
**Created:** [September 12, 2014, 7:14pm UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254 "2014-09-12T19:14:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![olsen\_chris](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/olsen_chris/32/9298_2.png) [@olsen\_chris](https://discuss.emberjs.com/u/olsen_chris)\
**Post date:** [September 12, 2014, 7:14pm UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/1 "2014-09-12T19:14:04Z")

</div>

Why is it that ember refuses to let me set a value for a checkbox?

I have a list of options that need to allow for selection, but when I try to use the following snippet embers throws an exception.

```
{{#each c in classes}}
  <label>
    {{input type="checkbox" name="selectedClasses[]" value=c.id}}
    {{name}}
  </label>
{{/each}}

```

Exception

```
Uncaught Error: Assertion Failed: {{input type='checkbox'}} does not support setting `value=someBooleanValue`; you must use `checked=someBooleanValue` instead. 

```

Is there a better way to do this with Ember?

---

<div class="post-metadata">

**Author:** ![rwjblue](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rwjblue/32/9411_2.png) [@rwjblue](https://discuss.emberjs.com/u/rwjblue)\
**Post date:** [September 12, 2014, 8:13pm UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/2 "2014-09-12T20:13:56Z")

</div>

Yes, as the error says use `checked` not `value`:

```handlebars
{{input type="checkbox" name="selectedClasses[]" checked=c.id}}

```

---

<div class="post-metadata">

**Author:** ![olsen\_chris](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/olsen_chris/32/9298_2.png) [@olsen\_chris](https://discuss.emberjs.com/u/olsen_chris)\
**Post date:** [September 12, 2014, 10:38pm UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/3 "2014-09-12T22:38:55Z")

</div>

That is what the error message says, but I am trying to set the **value** associated with the checkbox, not the checked status.

---

<div class="post-metadata">

**Author:** ![trabus](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/trabus/32/14963_2.png) [@trabus](https://discuss.emberjs.com/u/trabus)\
**Post date:** [September 13, 2014, 1:06am UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/4 "2014-09-13T01:06:41Z")

</div>

This looks like it could be a bug.

> [from MDN regarding the value attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input): The initial value of the control. This attribute is optional except when the value of the type attribute is radio or checkbox.

I looked through the [checkbox helper](https://github.com/emberjs/ember.js/blob/master/packages/ember-handlebars/lib/controls/checkbox.js) and didn’t see an `attributeBinding` for `value`. As I understand it, this attribute should be present for the checkbox input to represent a value. Am I missing something that ember is doing in the background?

---

<div class="post-metadata">

**Author:** ![Myrdhin](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/myrdhin/32/16107_2.png) [@Myrdhin](https://discuss.emberjs.com/u/Myrdhin)\
**Post date:** [April 9, 2016, 10:22am UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/5 "2016-04-09T10:22:18Z")

</div>

No change about ‘value’ attribute ? I use Ember 2.4.3 and this error is always here 😞

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [April 10, 2016, 4:04am UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/6 "2016-04-10T04:04:50Z")

</div>

You don’t really need the input helper at this point, you can use the native input elements.

```auto
<input
  type="checkbox"
  checked={{checked}}
  value={{value}}
  onchange={{action 'handleCheckboxChange' value='target.checked'}}
/>

```

---

<div class="post-metadata">

**Author:** ![Myrdhin](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/myrdhin/32/16107_2.png) [@Myrdhin](https://discuss.emberjs.com/u/Myrdhin)\
**Post date:** [April 10, 2016, 8:39am UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/7 "2016-04-10T08:39:22Z")

</div>

But this solution is only one-way binding on `booleanValue` CP (`checked` attribute). We must manage `booleanValue` in `handleCheckboxChange` too…

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [April 11, 2016, 2:37am UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/8 "2016-04-11T02:37:43Z")

</div>

You’ll always need to manage `checked`/`value` in some way either via a CP or inline helper (recommend you look at [ember-truth-helpers](https://www.npmjs.com/package/ember-truth-helpers) if you haven’t already). The example was just demonstrating using the native element. If you want to do two-way data binding you can – though I usually don’t to keep aligned with DDAU and to reduce future travelers from using observers to capture changes.

```auto
<input
  type='checkbox'
  checked={{checked}}
  value={{value}}
  onchange={{action (mut checked) value='target.checked'}}
/>

```

Two-way bound: [JS Bin - Collaborative JavaScript Debugging](http://jsbin.com/qezifunani/edit?html,js,output)

I’m a little unclear on the use of value here, are you doing a form POST? If not, I believe you can just rely on `checked` either as a computed property or an inlined helper. Otherwise, I’m curious to know your use case for value.

---

<div class="post-metadata">

**Author:** ![bhosky](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@bhosky](https://discuss.emberjs.com/u/bhosky)\
**Post date:** [June 30, 2016, 4:48am UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/9 "2016-06-30T04:48:12Z")

</div>

I know I am a late comer in this discussion, but I have been studying this issue and have found the following solution that some may find helpful. I wanted to find a solution that used the native Ember input helper for a checkbox {{input type=checkbox }} that could call an action that could manipulate values or class names or whatever else I fancied. I discovered as Chris did that you can not use ‘value=variable’ with the input helper. I also had no luck using action=“someAction” on=“click”. I tried many varieties of the action call but none worked. So finally this is what I came up with that achieved everything I wanted. As you can see it does not call an action but rather in the component controller it defines a variable to hold the boolean value for “checked”, and a method outside of the regular actions feature that simply observes the checked variable so that it fires whenever a change occurs which in this case is whenever the checkbox is clicked. I offer this because I has to look so hard and so long for a solution. I hope it helps those who are also looking for a solution. Peace. (Have no idea how you guys formatted your code with such a limited text editor 🙂 )

**In Component template hbs:**

{{input type=“checkbox” checked=myVal }}

**In Component Controller js file:**

myVal: false,

toggleCheckbox: function() {

```
 //change values or classes or whatever else you wish to do

```

}.observes(‘myVal’)

---

<div class="post-metadata">

**Author:** ![jameslaneconkling](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jameslaneconkling/32/11757_2.png) [@jameslaneconkling](https://discuss.emberjs.com/u/jameslaneconkling)\
**Post date:** [August 25, 2016, 4:53pm UTC](https://discuss.emberjs.com/t/checkbox-inputs-and-value-attributes/6254/10 "2016-08-25T16:53:16Z")

</div>

In case it’s of any help, you should be able to use the `{{input}}` helper and avoid 2-way data binding and observers, via something like (where `model` is any object the input form is supposed to be manipulating):

```auto
// template.hbs
{{input type="checkbox" checked=(readonly model.isChecked) click=(action 'checkboxClicked' model)}}

// component.js
actions: {
  checkboxClicked(model) {
    this.get('model').toggleProperty('isChecked');
    // do all the other things
  }
}

```
