Skip to content

Commit

Permalink
Merge pull request #185 from redding/kr-tweaks-form-js
Browse files Browse the repository at this point in the history
form: convention updates and a couple of bugfixes
  • Loading branch information
kellyredding authored and jcredding committed Oct 23, 2017
2 parents 32e0c58 + da743a7 commit 37bea79
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions assets/js/romo/form.js
@@ -1,5 +1,5 @@
var RomoForm = function(formElem, givenSubmitElems, givenSpinnerElems) {
this.elem = formElem;
var RomoForm = function(elem, givenSubmitElems, givenSpinnerElems) {
this.elem = elem;

var defaultSubmitElems = Romo.find(
this.elem,
Expand Down Expand Up @@ -29,7 +29,7 @@ var RomoForm = function(formElem, givenSubmitElems, givenSpinnerElems) {
}

this.doInit();
this._bindFormElem();
this._bindElem();

Romo.trigger(this.elem, 'romoForm:clearMsgs', [this]);
Romo.trigger(this.elem, 'romoForm:ready', [this]);
Expand All @@ -42,13 +42,13 @@ RomoForm.prototype.doInit = function() {
RomoForm.prototype.doSubmit = function() {
this.submitQueued = true;
if (this.submitRunning === false) {
this._doSubmit();
this._submit();
}
}

// private

RomoForm.prototype._bindFormElem = function() {
RomoForm.prototype._bindElem = function() {
this.submitElems.forEach(Romo.proxy(function(submitElem) {
Romo.on(submitElem, 'click', Romo.proxy(this._onSubmitClick, this));
}, this));
Expand Down Expand Up @@ -82,7 +82,7 @@ RomoForm.prototype._onSubmitClick = function(e) {
if (!Romo.hasClass(submitElem, 'disabled')) {
if (Romo.data(submitElem, 'romo-form-submit') === 'confirm') {
Romo.trigger(this.elem, 'romoForm:confirmSubmit', [this]);
} else
} else {
this.doSubmit();
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ RomoForm.prototype._onFormKeyPress = function(e) {
}
}

RomoForm.prototype._doSubmit = function() {
RomoForm.prototype._submit = function() {
this.submitQueued = false;
this.submitRunning = true;

Expand All @@ -127,20 +127,20 @@ RomoForm.prototype._doSubmit = function() {
Romo.trigger(this.elem, 'romoForm:beforeSubmit', [this]);

if(Romo.data(this.elem, 'romo-form-browser-submit') === true) {
this._doBrowserSubmit();
this._browserSubmit();
} else if (Romo.attr(this.elem, 'method').toUpperCase() === 'GET') {
this._doNonBrowserGetSubmit();
this._nonBrowserGetSubmit();
} else {
this._doNonBrowserNonGetSubmit();
this._nonBrowserNonGetSubmit();
}
}

RomoForm.prototype._doBrowserSubmit = function() {
RomoForm.prototype._browserSubmit = function() {
this.elem.submit();
Romo.trigger(this.elem, 'romoForm:browserSubmit', [this]);
}

RomoForm.prototype._doNonBrowserGetSubmit = function() {
RomoForm.prototype._nonBrowserGetSubmit = function() {
var formData = this._getFormData(this._getFormValues({ includeFiles: false }));

if (Romo.data(this.elem, 'romo-form-redirect-page') === true) {
Expand All @@ -154,17 +154,17 @@ RomoForm.prototype._doNonBrowserGetSubmit = function() {
Romo.redirectPage(Romo.attr(this.elem, 'action'));
}
} else {
this._doAjaxSubmit(formData);
this._ajaxSubmit(formData);
}
}

RomoForm.prototype._doNonBrowserNonGetSubmit = function() {
RomoForm.prototype._nonBrowserNonGetSubmit = function() {
var formData = this._getFormData(this._getFormValues({ includeFiles: true }));

this._doAjaxSubmit(formData);
this._ajaxSubmit(formData);
}

RomoForm.prototype._doAjaxSubmit = function(formData) {
RomoForm.prototype._ajaxSubmit = function(formData) {
Romo.ajax({
url: Romo.attr(this.elem, 'action'),
type: Romo.attr(this.elem, 'method'),
Expand All @@ -178,7 +178,7 @@ RomoForm.prototype._doAjaxSubmit = function(formData) {
RomoForm.prototype._onSubmitSuccess = function(response, status, xhr) {
Romo.trigger(this.elem, 'romoForm:clearMsgs');

var dataType = this._getXhrDataType(),
var dataType = this._getXhrDataType();
Romo.trigger(
this.elem,
'romoForm:submitSuccess',
Expand All @@ -192,7 +192,7 @@ RomoForm.prototype._onSubmitError = function(statusText, status, xhr) {
Romo.trigger(this.elem, 'romoForm:clearMsgs');

if(status === 422) {
var dataType = this._getXhrDataType(),
var dataType = this._getXhrDataType();
Romo.trigger(
this.elem,
'romoForm:submitInvalidMsgs',
Expand All @@ -212,7 +212,7 @@ RomoForm.prototype._onSubmitError = function(statusText, status, xhr) {
RomoForm.prototype._completeSubmit = function() {
Romo.trigger(this.elem, 'romoForm:submitComplete', [this]);
if (this.submitQueued === true) {
this._doSubmit();
this._submit();
} else {
this.submitRunning = false;
}
Expand Down

0 comments on commit 37bea79

Please sign in to comment.