Form submit radio inputs


#1

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.


#2

You can default your value in controller hook. https://guides.emberjs.com/v2.5.0/components/the-component-lifecycle/#toc_on-initial-render So you set your ‘aggregatorValue’ to you default value. this.set('aggregatorValue', "MAX") on initial route/component.


#3

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


#4

Are you sure you get with correct name??

You set in template aggregation and get in controller aggregator


#5

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

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

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


#6

For radio you need to use name attribute.

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


#7
{{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"


#8

Please check this out : simple radio button


#9

Thanks :slight_smile: