formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.22k stars 405 forks source link

Question: Setting field value #579

Closed gizburdt closed 8 years ago

gizburdt commented 8 years ago

Hi,

I'm working on an app with Google Maps. The thing I would like to do is, when the map center changes, set the latitude and longitude (both form fields).

I can listing on the center change, but how do I set the field value. How can I access the model property?

vm.map.addListener('center_changed', function(e){
    c = vm.map.getCenter()
    // Set model.latitude and model.longitude
});

Hope my question is clear. Thanks :)

benoror commented 8 years ago

Hi @gizburdt!

Do you mind creating an example of what you're trying to accomplish? Please follow the instructions here: http://help.angular-formly.com

This will make it easier for you to get help. Because the github issues are reserved for bug reports and feature requests, I'm going to go ahead and close this issue. See you on chat! Thanks!

benoror commented 8 years ago

@gizburdt Would't something like this be sufficient?

vm.map.addListener('center_changed', function(e){
    c = vm.map.getCenter()
    vm.model.latitude = c.latitude
    vm.model.longitude = c.longitude
});
gizburdt commented 8 years ago

Thanks for the reply, will have a look at the instructions. I tries your example. vm.model is undefined

benoror commented 8 years ago

That's a suggestion, it's hard for me to guess your implementation. An example would be suitable to get help :smile:

gizburdt commented 8 years ago

Here is a stripped version (only relevant code) of my application: https://jsbin.com/rucifufotu/edit?html,js,output

Thanks :)

benoror commented 8 years ago

You are not even loading Angular. Please follow this template: new-example.angular-formly.com

gizburdt commented 8 years ago

Here is my the working example: https://jsbin.com/kanuhu/21/edit?console,output

So the thing I would like to achieve is when the center of the map changes, the input gets filled with the latitude/longitude.

Thanks :)

benoror commented 8 years ago

Sure no problem :smile:, you had many typos and basic mistakes regarding angular itself and angular-formly. I fixed some of them: https://jsbin.com/tuwuyo/1/edit?html,js,console,output

If you want me to explain them let me know in Gitter. See you on chat!

gizburdt commented 8 years ago

Hi, thnx for the help! I'm new to angular (& formly), so I try to learn as much as possible. Also new to Gitter, how can we start a chat?

gizburdt commented 8 years ago

Got it working in my own app. And I understand what you did, so Gitter isn't necessary anymore :). I understand the $scope.$apply(), and I made a typo in my model="", I had spot, had to be vm.spot, or vm.model (add vm). Thanks again! :)

benoror commented 8 years ago

Np :smile: