@modular-forms/react
Version:
The modular and type-safe form library for React
20 lines (19 loc) • 554 B
JavaScript
import { removeInvalidNames } from './removeInvalidNames';
/**
* Returns a list with the names of all fields.
*
* @param form The form of the fields.
* @param shouldValid Whether to be valid.
*
* @returns All field names of the form.
*/
export function getFieldNames(form, shouldValid = true) {
// Get name of every field
const fieldNames = [...form.internal.fieldNames.peek()];
// Remove invalid field names
if (shouldValid) {
removeInvalidNames(form, fieldNames);
}
// Return field names
return fieldNames;
}