Skip to content

Commit

Permalink
feat(form): add a method to get a form field by name
Browse files Browse the repository at this point in the history
  • Loading branch information
cbourget authored and mbarbeau committed Aug 7, 2020
1 parent a61ce05 commit bb0e1bd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/common/src/lib/form/shared/form.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@ export function getAllFormFields(form: Form): FormField[] {
return form.groups.reduce((acc: FormField[], group: FormFieldGroup) => {
return acc.concat(group.fields);
}, [].concat(form.fields));
}

export function getFormFieldByName(form: Form, name: string): FormField {
const fields = getAllFormFields(form);
return fields.find((field: FormField) => {
return field.name === name;
});
}

0 comments on commit bb0e1bd

Please sign in to comment.