Last active
August 29, 2015 14:21
-
-
Save benoror/d845d5ae16c176e090d8 to your computer and use it in GitHub Desktop.
Getting $dirty fields from angular-formly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var dirtyFieldsIterator = function(obj, model) { | |
| angular.forEach(obj, function (el) { | |
| // fields | |
| if(el.fields) { | |
| fieldIterator(el.fields, model); | |
| } | |
| // fieldGroup | |
| if(el.fieldGroup) { | |
| // Nested model | |
| if(el.model) { // Model $eval at runtime | |
| model['nested'] = {}; // Instead of 'nested' should be `el.key` | |
| fieldIterator(el.fieldGroup, model['nested']); // "" | |
| } else { | |
| fieldIterator(el.fieldGroup, model); | |
| } | |
| } | |
| // Copy regular field's value | |
| if(el.formControl && el.formControl.$dirty) { | |
| model[el.key] = el.formControl.$modelValue || el.formControl.$viewValue; | |
| } | |
| }); | |
| }; | |
| var dirty_model = {}; | |
| dirtyFieldsIterator(vm.formFields, dirty_model); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment