Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
3c536bcc
Commit
3c536bcc
authored
Oct 07, 2016
by
Bryce Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve method naming in gl_field_errors.
parent
349caec3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
21 deletions
+22
-21
app/assets/javascripts/gl_field_errors.js.es6
app/assets/javascripts/gl_field_errors.js.es6
+22
-21
No files found.
app/assets/javascripts/gl_field_errors.js.es6
View file @
3c536bcc
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
initFieldValidation() {
initFieldValidation() {
// hidden when injected into DOM
// hidden when injected into DOM
this.inputElement.after(this.fieldErrorElement);
this.inputElement.after(this.fieldErrorElement);
this.inputElement.off('invalid').on('invalid', this.handleInvalid
Inpu
t.bind(this));
this.inputElement.off('invalid').on('invalid', this.handleInvalid
Submi
t.bind(this));
this.scopedSiblings = this.safelySelectSiblings();
this.scopedSiblings = this.safelySelectSiblings();
}
}
...
@@ -52,29 +52,25 @@
...
@@ -52,29 +52,25 @@
}
}
renderValidity() {
renderValidity() {
this.
setClearState
();
this.
renderClear
();
if (this.state.valid) {
if (this.state.valid) {
return this.
setValidState
();
return this.
renderValid
();
}
}
if (this.state.empty) {
if (this.state.empty) {
return this.
setEmptyState
();
return this.
renderEmpty
();
}
}
if (!this.state.valid) {
if (!this.state.valid) {
return this.
setInvalidState
();
return this.
renderInvalid
();
}
}
}
}
accessCurrentVal(newVal) {
handleInvalidSubmit(event) {
return newVal ? this.inputElement.val(newVal) : this.inputElement.val();
}
handleInvalidInput(event) {
event.preventDefault();
event.preventDefault();
const currentValue = this.accessCurrentVal();
const currentValue = this.accessCurrentVal
ue
();
this.state.valid = false;
this.state.valid = false;
this.state.empty = currentValue === '';
this.state.empty = currentValue === '';
...
@@ -86,36 +82,41 @@
...
@@ -86,36 +82,41 @@
}
}
/* Get or set current input value */
accessCurrentValue(newVal) {
return newVal ? this.inputElement.val(newVal) : this.inputElement.val();
}
getInputValidity() {
getInputValidity() {
return this.inputDomElement.validity.valid;
return this.inputDomElement.validity.valid;
}
}
updateValidity
State
() {
updateValidity() {
const inputVal = this.accessCurrentVal();
const inputVal = this.accessCurrentVal
ue
();
this.state.empty = !inputVal.length;
this.state.empty = !inputVal.length;
this.state.valid = this.getInputValidity();
this.state.valid = this.getInputValidity();
this.renderValidity();
this.renderValidity();
}
}
setValidState
() {
renderValid
() {
return this.
setClearState
();
return this.
renderClear
();
}
}
setEmptyState
() {
renderEmpty
() {
return this.
setInvalidState
();
return this.
renderInvalid
();
}
}
setInvalidState
() {
renderInvalid
() {
this.inputElement.addClass(inputErrorClass);
this.inputElement.addClass(inputErrorClass);
this.scopedSiblings.hide();
this.scopedSiblings.hide();
return this.fieldErrorElement.show();
return this.fieldErrorElement.show();
}
}
setClearState
() {
renderClear
() {
const inputVal = this.accessCurrentVal();
const inputVal = this.accessCurrentVal
ue
();
if (!inputVal.split(' ').length) {
if (!inputVal.split(' ').length) {
const trimmedInput = inputVal.trim();
const trimmedInput = inputVal.trim();
this.accessCurrentVal(trimmedInput);
this.accessCurrentVal
ue
(trimmedInput);
}
}
this.inputElement.removeClass(inputErrorClass);
this.inputElement.removeClass(inputErrorClass);
this.scopedSiblings.hide();
this.scopedSiblings.hide();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment