Add checks on submit button
authorThierry Florac <thierry.florac@onf.fr>
Wed, 07 May 2014 11:32:31 +0200
changeset 3 8f1aadf54f1b
parent 2 bfd612f2bd21
child 4 f2005bce25ae
Add checks on submit button
src/ztfy/myams/resources/js/myams.js
--- a/src/ztfy/myams/resources/js/myams.js	Wed May 07 11:31:48 2014 +0200
+++ b/src/ztfy/myams/resources/js/myams.js	Wed May 07 11:32:31 2014 +0200
@@ -912,7 +912,10 @@
 			// Remove remaining status messages
 			$('.alert, SPAN.state-error', form).remove();
 			$('.state-error', form).removeClassPrefix('state-');
-			$(form.data('ams-submit-button')).button('loading');
+			// Check submit button
+			var button = $(form.data('ams-submit-button'));
+			if (button)
+				button.button('loading');
 			ams.ajax.check($.fn.ajaxSubmit,
 						   ams.baseURL + 'ext/jquery-form-3.49' + (ams.devmode ? '.js' : '.min.js'),
 						   function() {
@@ -937,16 +940,23 @@
 										form_data = data.amsFormData || {};
 									}
 
+									var button = $(form.data('ams-submit-button'));
+									var buttonHandler,
+										buttonTarget;
+									if (button) {
+										buttonHandler = button.data('ams-form-handler');
+										buttonTarget = button.data('ams-form-submit-target');
+									}
+
 									var action = form.attr('action').replace(/#/, '');
 									if (action.startsWith(window.location.protocol))
 										var url = action;
 									else
 										url = ams.ajax.getAddr() + action;
-									var button = $(form.data('ams-submit-button'));
-									url += handler || button.data('ams-button-handler') || data.amsFormHandler || '';
+									url += handler || buttonHandler || data.amsFormHandler || '';
 
 									if (data.amsFormInitSubmitTarget) {
-										var target = $(button.data('ams-form-submit-target') || data.amsFormSubmitTarget || '#content');
+										var target = $(buttonTarget || data.amsFormSubmitTarget || '#content');
 										ams.executeFunctionByName(data.amsFormInitSubmit || 'MyAMS.form.initSubmit', form, target);
 									} else if (!data.amsFormHideSubmitFooter)
 										ams.executeFunctionByName(data.amsFormInitSubmit || 'MyAMS.form.initSubmitFooter', form);
@@ -980,6 +990,7 @@
 												ams.form.finalizeSubmitFooter.call(form);
 											}
 											form.data('submitted', false);
+											form.removeData('ams-submit-button');
 										},
 										success: function(result, status, request, form) {
 											var callback;
@@ -992,6 +1003,7 @@
 											if (form.is(':visible') && button)
 												button.button('reset');
 											form.data('submitted', false);
+											form.removeData('ams-submit-button');
 										},
 										iframe: hasUpload
 									}