This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Extend FormController's API to access list of form fields #14749
Closed
Description
Hello!
Thank you for your hard work!
I want to propose a feature to list fields of the form.
Right now we can access individual form fields using form[fieldName]
expression. However, form controller has a lot of properties and methods, so it's not possible to iterate the list of form fields directly.
I have to use this code to iterate all fields of the form:
var fields = ['firstName', 'lastName', 'email'];
angular.forEach(fields, function (fieldName) {
var field = form[fieldName];
// ...
});
However, it's a bad practice to hardcode array of field names this way.
The proposed API will allow us to do something like this:
angular.forEach(form.$fields, function (field) {
// ...
});
The other workaround is to iterate all properties of the form controller and detect ngModel objects, however it is also somewhat ugly.
I hope it makes sense. Thank you!