json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

How do I trigger onchange function for change in the model #967

Closed wioletag closed 6 years ago

wioletag commented 6 years ago

I have onChange function defined in the form that works fine when I change inputs on the GUI. onChange: function(modelValue,form) { $scope.formOnChange(modelValue, form); }

However, I need to update model programmatically to display some values that are coming from backend call, and I thought that onChange function would fire on this update but it is not happening. I cannot figure it out. How do I trigger it? This is how I'm updating values: $scope.model[key] = newValue;

thanks

Anthropic commented 6 years ago

The onChange is a field level change, if you want to watch the whole model then you would use a watch on your scope and trigger a function on the scope to make the change, which I would expect to cause a digest cycle. Or are you specifically wanting to trigger the onchange function in the form definition for the field? If so you may have to force it to run using something like these: https://stackoverflow.com/a/22942828/1383400

Please comment if you want to re-open or do not feel the question has been answered sufficiently.