This repository was archived by the owner on Apr 30, 2018. It is now read-only.
feat(formly-field): Adds parser for keys that contain arrays #709
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
This adds a deep assign function to formly-field that allows for keys that contain array indexes to properly create the array if it does not exist. It also adds a flag to formlyConfig.extras to enable this parser lowering the impact on existing installations.
Why
angular.$parse (used in the setter) does not differentiate between object and array when setting values. In the case where a key points to an array that has not already been set in the model it will create an object with a key of the index. This issue has been discussed many times in the angular project with the decision each time that they will not fix it. i.e. angular/angular.js#9850
How
In formly-field the function deepAssign has been added which recursively follows the path provided in the key establishing the proper object/array nodes if they do not exist, there is also a check function added to identify keys that contain array indexes. In formlyConfig.extras a flag called parseKeyArrays (defaulted to false) controls whether or not to utilize the deepAssign function in the setter so that existing implementations will not be affected.
For issue #706
Checklist:
angular.$parse does not (and will not angular/angular.js#9850) properly
handle arrays in keys unless they have already been created in the model. This fix/feature adds a
separate parser for these circumstances and a formlyConfig.extras flag to control its use. The flag
is in place to minimize impact on current functionality of the setter.
This is in support of #706