From cae80d9fcd1b643f07f9965bf46836f4ea623f3c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 16 Mar 2014 14:07:16 -0400 Subject: [PATCH] CRM-14215 - Add method to prevent ajax form submit --- CRM/Contact/Form/Task/PDFLetterCommon.php | 5 ++++- CRM/Core/Form.php | 16 ++++++++++++++++ CRM/Group/Form/Edit.php | 9 +++++++-- js/crm.ajax.js | 2 +- templates/CRM/Group/Page/Group.tpl | 4 ++-- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/Form/Task/PDFLetterCommon.php b/CRM/Contact/Form/Task/PDFLetterCommon.php index df180c918f..add5035ca5 100644 --- a/CRM/Contact/Form/Task/PDFLetterCommon.php +++ b/CRM/Contact/Form/Task/PDFLetterCommon.php @@ -69,11 +69,14 @@ class CRM_Contact_Form_Task_PDFLetterCommon { /** * Build the form * - * @access public + * @var CRM_Core_Form $form * * @return void */ static function buildQuickForm(&$form) { + // This form outputs a file so should never be submitted via ajax + $form->preventAjaxSubmit(); + //Added for CRM-12682: Add activity subject and campaign fields CRM_Campaign_BAO_Campaign::addCampaign($form); $form->add( diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 9d6e0603bd..8652af76a9 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1523,5 +1523,21 @@ class CRM_Core_Form extends HTML_QuickForm_Page { return array(); } } + + /** + * Sets form attribute + * @see CRM.loadForm + */ + function preventAjaxSubmit() { + $this->setAttribute('data-no-ajax-submit', 'true'); + } + + /** + * Sets form attribute + * @see CRM.loadForm + */ + function allowAjaxSubmit() { + $this->removeAttribute('data-no-ajax-submit'); + } } diff --git a/CRM/Group/Form/Edit.php b/CRM/Group/Form/Edit.php index f87214777e..ff4a18e62a 100644 --- a/CRM/Group/Form/Edit.php +++ b/CRM/Group/Form/Edit.php @@ -225,6 +225,11 @@ class CRM_Group_Form_Edit extends CRM_Core_Form { return; } + // We want the "new group" form to redirect the user + if ($this->_action == CRM_Core_Action::ADD) { + $this->preventAjaxSubmit(); + } + $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'title', ts('Name') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE @@ -467,7 +472,7 @@ WHERE title = %1 $potentialParentGroupIds = array_keys($groupNames); } - $parentGroupSelectValues = array('' => '- ' . ts('select') . ' -'); + $parentGroupSelectValues = array('' => '- ' . ts('select group') . ' -'); foreach ($potentialParentGroupIds as $potentialParentGroupId) { if (array_key_exists($potentialParentGroupId, $groupNames)) { $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId]; @@ -484,7 +489,7 @@ WHERE title = %1 else { $required = FALSE; } - $obj->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required); + $obj->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required, array('class' => 'crm-select2')); } return $parentGroups; diff --git a/js/crm.ajax.js b/js/crm.ajax.js index a19c80e1c5..c2518bbb6f 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -355,7 +355,7 @@ if (settings.validate) { $("form", this).validate(typeof(settings.validate) == 'object' ? settings.validate : CRM.validate.params); } - $("form", this).ajaxForm($.extend({ + $("form:not('[data-no-ajax-submit=true]')", this).ajaxForm($.extend({ url: data.url.replace(/reset=1[&]?/, ''), dataType: 'json', success: function(response) { diff --git a/templates/CRM/Group/Page/Group.tpl b/templates/CRM/Group/Page/Group.tpl index d25bbc16da..a5b8b8a19c 100644 --- a/templates/CRM/Group/Page/Group.tpl +++ b/templates/CRM/Group/Page/Group.tpl @@ -26,7 +26,7 @@ {* Actions: 1=add, 2=edit, browse=16, delete=8 *} {if $action ne 1 and $action ne 2 and $action ne 8 and $groupPermission eq 1}
-
{ts}Add Group{/ts}

+
{ts}Add Group{/ts}

{/if} {* action ne add or edit *}
@@ -47,7 +47,7 @@ {if $action ne 1 and $action ne 2 and $action ne 8 and $groupPermission eq 1} {/if} {* action ne add or edit *}
-- 2.25.1