Commit 3c536bcc authored by Bryce Johnson's avatar Bryce Johnson

Improve method naming in gl_field_errors.

parent 349caec3
...@@ -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.handleInvalidInput.bind(this)); this.inputElement.off('invalid').on('invalid', this.handleInvalidSubmit.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.accessCurrentValue();
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;
} }
updateValidityState() { updateValidity() {
const inputVal = this.accessCurrentVal(); const inputVal = this.accessCurrentValue();
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.accessCurrentValue();
if (!inputVal.split(' ').length) { if (!inputVal.split(' ').length) {
const trimmedInput = inputVal.trim(); const trimmedInput = inputVal.trim();
this.accessCurrentVal(trimmedInput); this.accessCurrentValue(trimmedInput);
} }
this.inputElement.removeClass(inputErrorClass); this.inputElement.removeClass(inputErrorClass);
this.scopedSiblings.hide(); this.scopedSiblings.hide();
......
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