New function works on a per-form basis, not per button.
It changes the button icon instead of the button text.
* @var bool
*
*/
-
protected $supportsActivitySeparation = TRUE;
+ public $submitOnce = TRUE;
+
/**
* Explicitly declare the entity api name.
*
'type' => 'upload',
'name' => ts('Save'),
'isDefault' => TRUE,
- 'submitOnce' => TRUE,
],
[
'type' => 'upload',
*/
public $_caseTypeId = NULL;
+ public $submitOnce = TRUE;
+
/**
* Explicitly declare the entity api name.
*/
*/
public $_contributionID;
+ public $submitOnce = TRUE;
+
/**
* @param $form
* @param $params
'name' => $contribButton,
'spacing' => ' ',
'isDefault' => TRUE,
- 'js' => ['onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"],
],
[
'type' => 'back',
];
// Add submit-once behavior when confirm page disabled
if (empty($this->_values['is_confirm_enabled'])) {
- $submitButton['js'] = ['onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"];
+ $this->submitOnce = TRUE;
}
//change button name for updating contribution
if (!empty($this->_ccid)) {
*/
protected $context;
+ /**
+ * @var bool
+ */
+ public $submitOnce = FALSE;
+
/**
* @return string
*/
) {
$this->setAttribute('data-warn-changes', 'true');
}
+
+ if ($this->submitOnce) {
+ $this->setAttribute('data-submit-once', 'true');
+ }
}
/**
$prevnext = $spacing = [];
foreach ($params as $button) {
if (!empty($button['submitOnce'])) {
- $button['js']['onclick'] = "return submitOnce(this,'{$this->_name}','" . ts('Processing') . "');";
+ $this->submitOnce = TRUE;
}
$attrs = ['class' => 'crm-form-submit'] + (array) CRM_Utils_Array::value('js', $button);
* @param string $nextType
* Button type for the form after processing.
* @param string $backType
- * @param bool|string $submitOnce If true, add javascript to next button submit which prevents it from being clicked more than once
+ * @param bool|string $submitOnce
*/
public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
$buttons = [];
'isDefault' => TRUE,
];
if ($submitOnce) {
- $nextButton['js'] = ['onclick' => "return submitOnce(this,'{$this->_name}','" . ts('Processing') . "');"];
+ $this->submitOnce = TRUE;
}
$buttons[] = $nextButton;
}
//add buttons
$js = NULL;
if ($this->isLastParticipant(TRUE) && empty($this->_values['event']['is_monetary'])) {
- $js = ['onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"];
+ $this->submitOnce = TRUE;
}
//handle case where user might sart with waiting by group
'name' => ts('Continue'),
'spacing' => ' ',
'isDefault' => TRUE,
- 'js' => $js,
],
]);
if ($includeSkipButton) {
*/
public $_totalAmount;
+ public $submitOnce = TRUE;
+
/**
* Monetary fields that may be submitted.
*
'type' => 'next',
'name' => $contribButton,
'isDefault' => TRUE,
- 'js' => ['onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"],
],
]);
) {
//freeze button to avoid multiple calls.
- $js = NULL;
-
if (empty($this->_values['event']['is_monetary'])) {
- $js = ['onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"];
+ $this->submitOnce = TRUE;
}
// CRM-11182 - Optional confirmation screen
'name' => $buttonLabel,
'spacing' => ' ',
'isDefault' => TRUE,
- 'js' => $js,
],
]);
}
*/
class CRM_SMS_Form_Schedule extends CRM_Core_Form {
+ public $submitOnce = TRUE;
+
/**
* Set variables up before form is built.
*/
'name' => ts('Submit Mass SMS'),
'spacing' => ' ',
'isDefault' => TRUE,
- 'js' => ['onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"],
],
[
'type' => 'cancel',
}
}
+var submitcount = 0;
/**
- * Function to change button text and disable one it is clicked
+ * Old submit-once function. Will be removed soon.
* @deprecated
- * @param obj object - the button clicked
- * @param formID string - the id of the form being submitted
- * @param string procText - button text after user clicks it
- * @return bool
*/
-var submitcount = 0;
-/* Changes button label on submit, and disables button after submit for newer browsers.
- Puts up alert for older browsers. */
function submitOnce(obj, formId, procText) {
// if named button clicked, change text
if (obj.value != null) {
});
};
+ // Submit-once
+ var submitted = [],
+ submitButton;
+ function submitOnceForm(e) {
+ if (e.isDefaultPrevented()) {
+ return;
+ }
+ if (_.contains(submitted, e.target)) {
+ return false;
+ }
+ submitted.push(e.target);
+ // Spin submit button icon
+ if (submitButton && $(submitButton, e.target).length) {
+ // Dialog button
+ if ($(e.target).closest('.ui-dialog .crm-ajax-container')) {
+ var identifier = $(submitButton).attr('name') || $(submitButton).attr('href');
+ if (identifier) {
+ submitButton = $(e.target).closest('.ui-dialog').find('button[data-identifier="' + identifier + '"]')[0] || submitButton;
+ }
+ }
+ $(submitButton).siblings('.crm-i').add('.crm-i, .ui-icon', submitButton).removeClass().addClass('crm-i fa-spinner fa-pulse');
+ }
+ }
+
// Initialize widgets
$(document)
.on('crmLoad', function(e) {
CRM.wysiwyg.create(this);
}
});
+ $('form[data-submit-once]', e.target).submit(submitOnceForm);
+ $('form[data-submit-once] input[type=submit]', e.target).click(function(e) {
+ submitButton = e.target;
+ });
})
.on('dialogopen', function(e) {
var $el = $(e.target);