Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model Populated by a Schema Default via Reference vs Copy #697

Closed
kyse opened this issue May 20, 2016 · 4 comments
Closed

Model Populated by a Schema Default via Reference vs Copy #697

kyse opened this issue May 20, 2016 · 4 comments

Comments

@kyse
Copy link
Contributor

kyse commented May 20, 2016

I am building out a custom model binding and am comparing objects to scope.schemaForm.schema object. I noticed when the model is initialized with defaults from the schema defaults, it's added to the model as a reference to the schema default object/array rather than copied. The result being, when a new object is being added to an array on the model and that array was created from the schema default, the schema object's default property will also include the new object.

Frankly I haven't dived into any of the validation code, but if it's basing any validation on the schema object that seems like an issue. Perhaps not, since I can't really see a reason to care about defaults when validating, but for my purpose, I'm comparing the object to the defaults to determine if I should consider the object for removal from the model (when the contained target property from the field input is empty string/null and the containing object is empty and not contained in the default).

I first thought I could just do a copy on the schema default from the builder, but seems like that object copy should happen when passsing the schema default value to sfSelect in the schemaForm directive (the line specifically: sfSelect(path, scope.model, prop['default']);). Otherwise, if I have nested objects in my schema each with a default of it's own, I end up with a schema default object with properties not originally defined in the schema.

@Anthropic
Copy link
Member

Anthropic commented May 23, 2016

@kyse I believe this is already known via #407
Can you confirm if that is the case or not and re-open to comment further if it is different please?

@tjones0808
Copy link

was this fixed? I am still having the same problem.

@kyse
Copy link
Contributor Author

kyse commented Aug 31, 2016

I never saw any end in sight to all these updates needed. Doesn't appear they do very many publishes either. So I just work on a manually modified version of the library to address this myself and prevent bower from updating the library unless I do so manually to readdress my modifications.

@kyse
Copy link
Contributor Author

kyse commented Aug 31, 2016

Line 2667: sfSelect(path, scope.model, angular.copy(prop['default']));

My other modification is to prevent killing the titleMap but parse properties to see what needs updating on line 2393 to 2399.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants