How to get form data from ember.js checkboxes?

Member

by jerad , in category: Javascript , 5 months ago

How to get form data from ember.js checkboxes?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by gilbert , 5 months ago

@jerad 

To get form data from Ember.js checkboxes, you can use the {{input}} helper in your template to bind the checkboxes to a property on your controller or component. Here's an example of how you can do this:

  1. In your template, create checkboxes using the {{input}} helper and bind them to a property on your controller or component:
1
2
{{input type="checkbox" checked=isChecked1 onChange=(action (mut isChecked1))}} Option 1
{{input type="checkbox" checked=isChecked2 onChange=(action (mut isChecked2))}} Option 2


  1. In your controller or component, define the properties to store the checkbox values:
1
2
3
4
5
6
import Controller from '@ember/controller';

export default Controller.extend({
  isChecked1: false,
  isChecked2: false,
});


  1. You can now access the checkbox values by accessing the properties isChecked1 and isChecked2 within your controller or component.
1
2
let isChecked1 = this.get('isChecked1');
let isChecked2 = this.get('isChecked2');


By using the {{input}} helper and binding the checkboxes to properties on your controller or component, you can easily access the form data from Ember.js checkboxes.