From e0aa05fb6567fcbb92856a4fc4712a69640d2d03 Mon Sep 17 00:00:00 2001 From: JKingsnorth Date: Thu, 18 Aug 2016 17:32:04 +0100 Subject: [PATCH] CRM-19179: Only allow one 'set primary' to be checked per entity --- templates/CRM/Contact/Form/Merge.tpl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/templates/CRM/Contact/Form/Merge.tpl b/templates/CRM/Contact/Form/Merge.tpl index 733b515399..e3f67197b4 100644 --- a/templates/CRM/Contact/Form/Merge.tpl +++ b/templates/CRM/Contact/Form/Merge.tpl @@ -364,6 +364,25 @@ return result; } + /** + * Called when a 'set primary' checkbox is clicked in order to disable any + * other 'set primary' checkboxes for blocks of the same entity. So don't let + * users try to set two different phone numbers as primary on the form. + */ + function updateSetPrimaries() { + var nameSplit = event.target.name.split('['); + var blockName = nameSplit[1].slice(0, -1); + var controls = CRM.$('span.location_block_controls[id^="main_' + blockName + '"]'); + + // Enable everything + controls.find('input[id$="[set_other_primary]"]:not(:checked)').removeAttr("disabled"); + + // If one is checked, disable the others + if (controls.find('input[id$="[set_other_primary]"]:checked').length > 0) { + controls.find('input[id$="[set_other_primary]"]:not(:checked)').attr("disabled", "disabled"); + } + } + CRM.$(function($) { $('table td input.form-checkbox').each(function() { @@ -396,12 +415,18 @@ // Call mergeBlock whenever a location type is changed $('body').on('change', 'select[id$="locTypeId"],select[id$="typeTypeId"],input[id$="[operation]"],input[id$="[set_other_primary]"]', function(){ + // All the information we need is held in the id, separated by underscores var nameSplit = this.name.split('['); + // Lookup the main value, if any are available if (allBlock[nameSplit[1].slice(0, -1)] != undefined) { updateMainLocationBlock(nameSplit[1].slice(0, -1), nameSplit[2].slice(0, -1)); } + + // Update all 'set primary' checkboxes + updateSetPrimaries(); + }); }); -- 2.25.1