Form submit radio inputs

Hi, I have a form to submit, I cat retrieve all input values except the radio inputs… Here is example:

Form:

 <form {{action 'execute' this on="submit"}} class="form">
 {{input type="text" value=tokenId}}

{{input type="radio" name="aggregation" value='AVG'}}
{{input type="radio" name="aggregation" value='MAX'}}
<button>Execute</button>
</form>

Controller: actions: { execute(){

      console.log('e tokenId', this.get('tokenId'));
      console.log('e aggregator2', this.get('aggregator'));
 
    }
  }

So I need the aggregation input data, witch is selected… I thought I could set default value for input like this: {{input type="radio" name="aggregation" value=aggregation="MAX"}}

But noway.

You can default your value in controller hook. The Component Lifecycle - Components - Ember Guides So you set your ‘aggregatorValue’ to you default value. this.set('aggregatorValue', "MAX") on initial route/component.

Yes, I can. It will assign values, but how do I get the selected value on submit?

Are you sure you get with correct name??

You set in template aggregation and get in controller aggregator

As I understood I get value by getting by value… Like this:

{{input type="text" value=tokenId}}

console.log('e tokenId', this.get('tokenId'));

For radio you need to use name attribute.

Here you get a different property : console.log('e aggregator2', this.get('aggregator'));

{{input type="radio" name="aggregation" value='AVG'}}
{{input type="radio" name="aggregation" value='MAX'}}

Calling for

console.log('e aggregator3', this.get('aggregation'));

Getting ''undefined"

Please check this out : simple radio button

2 Likes

Thanks :slight_smile: