mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2025-04-11 14:01:36 +02:00
LSform: fix non-AJAX form submission (or form with input[type=file])
This commit is contained in:
parent
060ebf1bff
commit
00132e32ad
1 changed files with 11 additions and 5 deletions
|
@ -38,6 +38,7 @@ var LSform = new Class({
|
||||||
this.params={};
|
this.params={};
|
||||||
}
|
}
|
||||||
this._ajaxSubmit=this.params.ajaxSubmit;
|
this._ajaxSubmit=this.params.ajaxSubmit;
|
||||||
|
LSdebug('LSform('+this.idform+'): ajaxSubmit='+this._ajaxSubmit);
|
||||||
|
|
||||||
this.warnBox = new LSinfosBox({
|
this.warnBox = new LSinfosBox({
|
||||||
name: 'LSformWarnBox',
|
name: 'LSformWarnBox',
|
||||||
|
@ -282,8 +283,8 @@ var LSform = new Class({
|
||||||
onSubmit: function(event) {
|
onSubmit: function(event) {
|
||||||
if (this.submit_confirmed) {
|
if (this.submit_confirmed) {
|
||||||
// On non-ajax form, leave form submitting if already confirmed
|
// On non-ajax form, leave form submitting if already confirmed
|
||||||
LSdebug('onSubmit(): form submission already confirmed');
|
LSdebug('onSubmit(): form submission already confirmed, do not stop submit event');
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop form submitting event
|
// Stop form submitting event
|
||||||
|
@ -297,7 +298,7 @@ var LSform = new Class({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.submitting = true;
|
this.submitting = true;
|
||||||
console.log(this.LSform);
|
LSdebug(this.LSform);
|
||||||
this.LSform.addClass('submitting');
|
this.LSform.addClass('submitting');
|
||||||
|
|
||||||
// Fire
|
// Fire
|
||||||
|
@ -306,6 +307,7 @@ var LSform = new Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
onSubmitConfirm: function (confirmed, event) {
|
onSubmitConfirm: function (confirmed, event) {
|
||||||
|
LSdebug("onSubmitConfirm("+confirmed+")");
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
this.submitting = false;
|
this.submitting = false;
|
||||||
this.LSform.removeClass('submitting');
|
this.LSform.removeClass('submitting');
|
||||||
|
@ -316,6 +318,7 @@ var LSform = new Class({
|
||||||
this.checkUploadFileDefined();
|
this.checkUploadFileDefined();
|
||||||
|
|
||||||
if (this._ajaxSubmit) {
|
if (this._ajaxSubmit) {
|
||||||
|
LSdebug("onSubmitConfirm(): AJAX submission enabled");
|
||||||
this.LSformAjaxInput = new Element('input');
|
this.LSformAjaxInput = new Element('input');
|
||||||
this.LSformAjaxInput.setProperties ({
|
this.LSformAjaxInput.setProperties ({
|
||||||
type: 'hidden',
|
type: 'hidden',
|
||||||
|
@ -333,17 +336,20 @@ var LSform = new Class({
|
||||||
this.LSform.send();
|
this.LSform.send();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
LSdebug("onSubmitConfirm(): AJAX submission disabled");
|
||||||
if($type(this.LSformAjaxInput)) {
|
if($type(this.LSformAjaxInput)) {
|
||||||
this.LSformAjaxInput.dispose();
|
this.LSformAjaxInput.dispose();
|
||||||
}
|
}
|
||||||
this.submit_confirmed = true;
|
this.submit_confirmed = true;
|
||||||
this.LSform.fireEvent('submit');
|
LSdebug("onSubmitConfirm("+confirmed+"): non-AJAX form, submit form again with submit_confirmed flag == TRUE.");
|
||||||
|
this.LSform.submit();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
checkUploadFileDefined: function() {
|
checkUploadFileDefined: function() {
|
||||||
this.LSform.getElements('input[type=file]').each(function(ipt) {
|
this.LSform.getElements('input[type=file]').each(function(ipt) {
|
||||||
if (ipt.files.length!=0) {
|
if (ipt.files.length!=0) {
|
||||||
|
LSdebug("checkUploadFileDefined(): input[type=file] detected, disable AJAX submit.");
|
||||||
this._ajaxSubmit=0;
|
this._ajaxSubmit=0;
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
@ -503,9 +509,9 @@ var LSform = new Class({
|
||||||
final_result = false;
|
final_result = false;
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
LSdebug('LSform :: onFinalEventListenerCallback('+event+'): final result = '+final_result);
|
|
||||||
|
|
||||||
// Run final callback
|
// Run final callback
|
||||||
|
LSdebug('LSform :: onFinalEventListenerCallback('+event+'): run final_callback with final result = '+final_result);
|
||||||
final_callback(final_result, event);
|
final_callback(final_result, event);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue