Namit
Namit

Reputation: 53

Angular send only changed fields of model or Replicate model with change

I prepared the form through angular.But when I need to submit the form so how can I send only all changed field or selected option values. Need Some thing which works in all Scenario of input form fields.

DEMO: demo for ref.

on click of save how can i get it something like below one

{"list":[{"selectedOption":{"id":[]}}],"active":true,"chk_list":[{"selectedOption":{"id":["2","3"]}}],"name":"ssss"}

Upvotes: 0

Views: 2057

Answers (2)

Isha Aggarwal
Isha Aggarwal

Reputation: 452

If you want the object to be returned to have only specific fields, then the result object should be different from the "myData" object, that you are using to actually display all the possible options to the user, etc.

Try this : http://jsfiddle.net/tc7dhep3/

I have created another variable $scope.result that contains the info to be sent on save button click.

Upvotes: 1

Fals
Fals

Reputation: 6839

The $dirty property for input elements tell if the user interacted with this, you can use this property to say which field was modified.

frm.name.$dirty

Angular doc: input - directive in module ng

You can combine this with ng-change or ng-submit to build the post object

Exemple: DEMO Forked from yours

Upvotes: 0

Related Questions