0
votes

I need read a second value from a input and to do a search. So my component load a complementar info. Follow the form.

<form class="col-md-12 form-group">
   {{input type="text" classNames="form-control" placeholder="Place name" name="placeName" }}
   {{input type="text" class="form-control" placeholder="09111-620" name="zipcode" focus-out="searchPlace"}}
</form>

I need access placeName in focus-outaction. How I do this, after several search in google I don't see a solution using ember 2.

2

2 Answers

1
votes

it is simple

{{input value=placeNameVal focus-out='placeNameFocusedOut'}} 
{{input value=zipcodeVal focus-out='zipcodeFocusedOut'}} 

in route or controller

actions: {
  zipcodeFocusedOut(zipcodeVal){
   console.log(zipcodeVal);
   console.log(this.get('placeNameVal')); // if you want to get other val
  },
  placeNameFocusedOut(placeNameVal) {
   console.log(placeNameVal);
   console.log(this.get('zipcodeVal')); // if you want to get other val
  }
}
0
votes

I'm assuming that you want to be able to access whatever is currently in the Place Name field from within your zipcodeFocusedOut action. To do this, you can bind the 'value' attribute of the text field as a property on your route or controller. In your template:

<form class="col-md-12 form-group">
   {{input type="text" classNames="form-control" value=placeNameValue placeholder="Place name" name="placeName" }}
   {{input type="text" class="form-control" placeholder="09111-620" name="zipcode" focus-out="searchPlace"}}
</form>

Instantiate that property as blank in your route or controller, and then you'll be able to refer to it in the action function:

in route or controller:

placeNameValue: '',

actions: {
  zipcodeFocusedOut(zipcodeVal){
   console.log(this.get('placeNameValue');
  }
}

Any time the text field value is changed, it will automatically change the associated placeNameValue field. In other words, this.get('placeNameValue') will always represent the current value of that field, and you can access this anywhere within your controller/route.