Commit 503dcaca authored by Bryce Johnson's avatar Bryce Johnson

Properly implement focus on first invalid.

parent 80cbc983
...@@ -53,17 +53,16 @@ ...@@ -53,17 +53,16 @@
return this.setInvalidState(); return this.setInvalidState();
} }
this.form.focusOnFirstInvalid.apply(this.form);
} }
handleInvalidInput(event) { handleInvalidInput(event) {
event.preventDefault(); event.preventDefault();
const currentValue = this.inputElement.val();
this.state.valid = false; this.state.valid = false;
this.state.empty = false; this.state.empty = currentValue === '';
this.renderValidity(); this.renderValidity();
this.form.focusOnFirstInvalid.apply(this.form);
// For UX, wait til after first invalid submission to check each keyup // For UX, wait til after first invalid submission to check each keyup
this.inputElement.off('keyup.field_validator') this.inputElement.off('keyup.field_validator')
.on('keyup.field_validator', this.updateValidityState.bind(this)); .on('keyup.field_validator', this.updateValidityState.bind(this));
...@@ -76,7 +75,7 @@ ...@@ -76,7 +75,7 @@
updateValidityState() { updateValidityState() {
const inputVal = this.inputElement.val(); const inputVal = this.inputElement.val();
this.state.empty = !!inputVal.length; this.state.empty = !inputVal.length;
this.state.valid = this.getInputValidity(); this.state.valid = this.getInputValidity();
this.renderValidity(); this.renderValidity();
} }
...@@ -105,10 +104,6 @@ ...@@ -105,10 +104,6 @@
this.inputElement.siblings('p').hide(); this.inputElement.siblings('p').hide();
this.fieldErrorElement.hide(); this.fieldErrorElement.hide();
} }
checkFieldValidity(target) {
return target.validity.valid;
}
} }
const customValidationFlag = 'no-gl-field-errors'; const customValidationFlag = 'no-gl-field-errors';
...@@ -144,8 +139,8 @@ ...@@ -144,8 +139,8 @@
} }
focusOnFirstInvalid () { focusOnFirstInvalid () {
const firstInvalid = this.state.inputs.find((input) => !input.inputDomElement.validity.valid); const firstInvalid = this.state.inputs.filter((input) => !input.inputDomElement.validity.valid)[0];
$(firstInvalid).focus(); firstInvalid.inputElement.focus();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment