@atlaskit/form
Version:
A form allows people to input information.
19 lines (17 loc) • 578 B
JavaScript
import { getIn } from 'final-form';
export const getFirstErrorField = (inputs, errors) => {
// Guaranteed to be of type HTMLInputElement[] due to getInputs function overrided in createDecorator
let htmlInputs = inputs;
return htmlInputs.find(function (input) {
// If input is hidden, do not focus
if (input.type === 'hidden') {
return false;
}
// If input ID matches the error, focus
if (input.id && getIn(errors, input.id)) {
return true;
}
// Default to base behavior
return input.name && getIn(errors, input.name);
});
};