Skip to content

Instantly share code, notes, and snippets.

@xantiagoma
Last active December 13, 2018 18:52
Show Gist options
  • Save xantiagoma/aece31e5a3038529cb84ea36b93f9130 to your computer and use it in GitHub Desktop.
Save xantiagoma/aece31e5a3038529cb84ea36b93f9130 to your computer and use it in GitHub Desktop.
While debug copy & paste functions
// Select <gh-event> in Elements panel then in
// Console paste:
var eventForm = ng.probe($0).componentInstance.eventForm;
var FormArray = eventForm.constructor;
var FormGroup = eventForm.controls[0].constructor;
var findInvalidControlsRecursive = function findInvalidControlsRecursive(formToInvestigate) {
var invalidControls = [];
var recursiveFunc = function (form) {
Object.keys(form.controls).forEach(function (field) {
var control = form.get(field);
if (control.invalid)
invalidControls.push(field);
if (control instanceof FormGroup) {
recursiveFunc(control);
}
else if (control instanceof FormArray) {
recursiveFunc(control);
}
});
};
recursiveFunc(formToInvestigate);
return invalidControls;
};
findInvalidControlsRecursive(eventForm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment