69e4072f89
* master: (389 commits)
Document "No gems fetched from git repositories" policy [ci skip]
Typos
Small gramatical tweaks
Typos
Added PHP & NPM doc
Use `:empty_project` where possible in request specs
Add caching of droplab ajax requests
Use `:empty_project` where possible in model specs
Revert 3f17f29a
Remove unused js response from refs controller
Add MR id to changelog entry
fixed small mini pipeline graph line glitch
Prevent form to be submitted twice
Fix Error 500 when repositories contain annotated tags pointing to blobs
Fix /explore sorting (trending)
Simplify wording in "adding an image" docs
Remove "official merge window" from CONTRIBUTING.md [ci skip]
Update repository check documentation
Fixed flexbox and wrap issues
Update two_factor_authentication.md
...
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
/* eslint-disable comma-dangle, class-methods-use-this, max-len, space-before-function-paren, arrow-parens, no-param-reassign */
|
|
|
|
require('./gl_field_error');
|
|
|
|
((global) => {
|
|
const customValidationFlag = 'gl-field-error-ignore';
|
|
|
|
class GlFieldErrors {
|
|
constructor(form) {
|
|
this.form = $(form);
|
|
this.state = {
|
|
inputs: [],
|
|
valid: false
|
|
};
|
|
this.initValidators();
|
|
}
|
|
|
|
initValidators () {
|
|
// register selectors here as needed
|
|
const validateSelectors = [':text', ':password', '[type=email]']
|
|
.map((selector) => `input${selector}`).join(',');
|
|
|
|
this.state.inputs = this.form.find(validateSelectors).toArray()
|
|
.filter((input) => !input.classList.contains(customValidationFlag))
|
|
.map((input) => new global.GlFieldError({ input, formErrors: this }));
|
|
|
|
this.form.on('submit', this.catchInvalidFormSubmit);
|
|
}
|
|
|
|
/* Neccessary to prevent intercept and override invalid form submit
|
|
* because Safari & iOS quietly allow form submission when form is invalid
|
|
* and prevents disabling of invalid submit button by application.js */
|
|
|
|
catchInvalidFormSubmit (event) {
|
|
if (!event.currentTarget.checkValidity()) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
}
|
|
|
|
focusOnFirstInvalid () {
|
|
const firstInvalid = this.state.inputs.filter((input) => !input.inputDomElement.validity.valid)[0];
|
|
firstInvalid.inputElement.focus();
|
|
}
|
|
}
|
|
|
|
global.GlFieldErrors = GlFieldErrors;
|
|
})(window.gl || (window.gl = {}));
|