Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryce Johnson <bryce@gitlab.com>2016-09-28 13:59:58 +0300
committerBryce Johnson <bryce@gitlab.com>2016-10-15 09:28:52 +0300
commit503dcacaa42bc5870a87b579009c53c991b03c4e (patch)
tree34080bd032109ae8127b9c1f78bd37536e51803a
parent80cbc9838eae8836a9bf85bac1dca7e965d1d77d (diff)
Properly implement focus on first invalid.
-rw-r--r--app/assets/javascripts/gl_field_errors.js.es617
1 files changed, 6 insertions, 11 deletions
diff --git a/app/assets/javascripts/gl_field_errors.js.es6 b/app/assets/javascripts/gl_field_errors.js.es6
index e1de7f78efc..91c25047f7b 100644
--- a/app/assets/javascripts/gl_field_errors.js.es6
+++ b/app/assets/javascripts/gl_field_errors.js.es6
@@ -53,17 +53,16 @@
return this.setInvalidState();
}
- this.form.focusOnFirstInvalid.apply(this.form);
}
handleInvalidInput(event) {
event.preventDefault();
-
+ const currentValue = this.inputElement.val();
this.state.valid = false;
- this.state.empty = false;
+ this.state.empty = currentValue === '';
this.renderValidity();
-
+ this.form.focusOnFirstInvalid.apply(this.form);
// For UX, wait til after first invalid submission to check each keyup
this.inputElement.off('keyup.field_validator')
.on('keyup.field_validator', this.updateValidityState.bind(this));
@@ -76,7 +75,7 @@
updateValidityState() {
const inputVal = this.inputElement.val();
- this.state.empty = !!inputVal.length;
+ this.state.empty = !inputVal.length;
this.state.valid = this.getInputValidity();
this.renderValidity();
}
@@ -105,10 +104,6 @@
this.inputElement.siblings('p').hide();
this.fieldErrorElement.hide();
}
-
- checkFieldValidity(target) {
- return target.validity.valid;
- }
}
const customValidationFlag = 'no-gl-field-errors';
@@ -144,8 +139,8 @@
}
focusOnFirstInvalid () {
- const firstInvalid = this.state.inputs.find((input) => !input.inputDomElement.validity.valid);
- $(firstInvalid).focus();
+ const firstInvalid = this.state.inputs.filter((input) => !input.inputDomElement.validity.valid)[0];
+ firstInvalid.inputElement.focus();
}
}