Skip to content
Snippets Groups Projects
Commit f6c699af authored by mattwire's avatar mattwire
Browse files

Fix jQuery validation on checkboxes in 'On behalf of' profiles

parent c8e08281
No related branches found
No related tags found
1 merge request!144Fix jQuery validation on checkboxes in 'On behalf of' profiles
...@@ -654,28 +654,31 @@ ...@@ -654,28 +654,31 @@
} }
function resetBillingFieldsRequiredForJQueryValidate() { function resetBillingFieldsRequiredForJQueryValidate() {
// The "name" parameter on a set of checkboxes where at least one must be checked must be the same or validation will require all of them! // The "name" parameter on a group of checkboxes where at least one must be checked must be the same or validation will require all of them!
// (But we have to reset this back before we submit otherwise the submission has no data (that's a Civi issue I think). // Reset the name of the checkboxes before submitting otherwise CiviCRM will not get the checkbox values.
$('div#priceset input[type="checkbox"], fieldset.crm-profile input[type="checkbox"]').each(function() { $('div#priceset input[type="checkbox"], fieldset.crm-profile input[type="checkbox"], #on-behalf-block input[type="checkbox"]').each(function() {
CRM.$(this).attr('name', CRM.$(this).attr('name') + '[' + CRM.$(this).attr('id').split('_').pop() + ']'); if ($(this).attr('data-name') !== undefined) {
CRM.$(this).removeAttr('required'); $(this).attr('name', $(this).attr('data-name'));
CRM.$(this).removeClass('required'); }
CRM.$(this).removeAttr('aria-required');
}); });
} }
function setBillingFieldsRequiredForJQueryValidate() { function setBillingFieldsRequiredForJQueryValidate() {
// Work around https://github.com/civicrm/civicrm-core/compare/master...mattwire:stripe_147 // CustomField checkboxes in profiles do not get the "required" class.
// The main billing fields do not get set to required so don't get checked by jquery validateform. // This should be fixed in CRM_Core_BAO_CustomField::addQuickFormElement but requires that the "name" is fixed as well.
// This also applies to any radio button in billing/profiles so we flag every element with a crm-marker
// See also https://github.com/civicrm/civicrm-core/pull/16488 for a core fix
$('div.label span.crm-marker').each(function() { $('div.label span.crm-marker').each(function() {
$(this).closest('div').next('div').find('input').addClass('required'); $(this).closest('div').next('div').find('input[type="checkbox"]').addClass('required');
}); });
// The "name" parameter on a set of checkboxes where at least one must be checked must be the same or validation will require all of them! // The "name" parameter on a set of checkboxes where at least one must be checked must be the same or validation will require all of them!
// (But we have to reset this back before we submit otherwise the submission has no data (that's a Civi issue I think). // Checkboxes for custom fields are added as quickform "advcheckbox" which seems to require a unique name for each checkbox. But that breaks
$('div#priceset input[type="checkbox"], fieldset.crm-profile input[type="checkbox"]').each(function() { // jQuery validation because each checkbox in a required group must have the same name.
$(this).attr('name', $(this).attr('name').split('[').shift()); // We store the original name and then change it. resetBillingFieldsRequiredForJQueryValidate() must be called before submit.
// Most checkboxes get names like: "custom_63[1]" but "onbehalf" checkboxes get "onbehalf[custom_63][1]". We change them to "custom_63" and "onbehalf[custom_63]".
$('div#priceset input[type="checkbox"], fieldset.crm-profile input[type="checkbox"], #on-behalf-block input[type="checkbox"]').each(function() {
var name = $(this).attr('name');
$(this).attr('data-name', name);
$(this).attr('name', name.replace('[' + name.split('[').pop(), ''));
}); });
// @todo remove once min version is 5.28 (https://github.com/civicrm/civicrm-core/pull/17672) // @todo remove once min version is 5.28 (https://github.com/civicrm/civicrm-core/pull/17672)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment