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

global ngModelOptions ignored when ngModelOptions provided in field definition. #792

Open kyse opened 7 years ago

kyse commented 7 years ago

So I have a need to add the tab index a fied resides on to the ngModelOptions so when its time to validate, I can ignore specific validation errors by parsing the errors array, which contains error codes, which in turn contains the array of ngModelController objects specific to that error. I can grab the fields tab from the ngModelController.$options to check the tab it's part of and know if I should ignore it or not.

Problem is I noticed when I add the ngModelOptions property to the field's form definition, it ends up not applying the global formDefaults' ngModelOptions property on it.

I believe the offending spot is under the sfPathProvider, inside the $get method's postProcessFn method.

It parses through obj.keys, and when obj[attr] === undefined, it applies the schemaDefaults (lookup's saved stdForm object) attribute to it. Seems like it would be good to set ngModelOptions property as a merge between the stdForm settings to capture the global form settings, and also pass in the field's for definition specific options if they exist.

Which leads to the inquiry, besides updating the schema forms file to merge the ngModelOptions, is there another way to lookup the form definition settings when all I have is the ngModelController of that field? Also have a need to grab the path somehow.

Anthropic commented 7 years ago

Hi @kyse are you referring to within a directive of your own? Without knowing that I would be thinking about importing the sfField scope for the info.

Thanks for the info on the merge script issue, that does seem like something worth updating, the script is now in json-schema-form-core in the merge.js file and the options attribute passed into the merge function is whatever is added to the sf-options attribute, so it would be relatively easy to change.

I will make this issue an enhancement and take a look at updating it tonight :)

kyse commented 7 years ago

Yes inside a directive, once I broadcast for the form to validate, if there are errors, I'm checking the formController's $errors array to grab all the ngModelControllers. I think I may go about this differently, and just store the form definition for that field in a factory so I can easily look it up. Since I'm using custom GetterSetter's to apply the model value so I can make use of customized array targeting, the built in lookup store you guys use gets overridden since my keys can be Entity.Person[].FirstName.

Anthropic commented 7 years ago

There is an issue kicking about regarding showing form status on a tab for the validity of the form within its tab pane, the solution offered in that may be of interest to you as well perhaps. Different use case but still involving the $errors array.