From 888607cf39f763c099da36c4b9ceeb36b4b2751d Mon Sep 17 00:00:00 2001 From: rjy7 Date: Mon, 12 Apr 2010 23:49:23 +0000 Subject: [PATCH] NIHVIVO-360 Merge changes from rel-1.0-maint branch: Fixed custom form javascript so required hint spans get removed on cancel in IE. IE transforms the text inserted in the html() call, so a string replace was not removing them. --- productMods/edit/forms/js/customForm.js | 40 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/productMods/edit/forms/js/customForm.js b/productMods/edit/forms/js/customForm.js index a76b5d35..a31c6ff2 100644 --- a/productMods/edit/forms/js/customForm.js +++ b/productMods/edit/forms/js/customForm.js @@ -53,6 +53,7 @@ var customForm = { COMBINED: 3 }, + onLoad: function() { this.initObjects(); @@ -76,7 +77,7 @@ var customForm = { this.existingSelect = this.existing.children('select'); this.addNew = $('.new'); this.entry = $('.entry'); - this.existingOrNew = $('.existingOrNew'); + this.existingOrNew = $('.existingOrNew'); // just the word "or" between existing and add new this.cancel = this.form.find('.cancel'); this.requiredHints = this.form.find('.requiredHint'); @@ -289,23 +290,42 @@ var customForm = { // Use when the non-Javascript version should not show the required hint, // because the field is not required in that version (e.g., it's one of two // fields, where one of the two must be filled in but neither one is required). + // Showing the asterisks cannot simply be done once on page load, because in + // step 1 the select existing field should not be marked required. // Arguments: action = 'add' or 'remove' // Varargs: element(s) toggleRequiredHints: function(action /* elements */) { var labelText, - newLabelText, + newLabelText, requiredHintText = ' *', - numArgs = arguments.length; + numArgs = arguments.length, + element, + el; - for (var i = 1; i < numArgs; i++) { - arguments[i].find('label.required').each(function() { - labelText = $(this).html(); - newLabelText = action == 'add' ? labelText + requiredHintText : - labelText.replace(requiredHintText, ''); - $(this).html(newLabelText); - }); + for (var i = 1; i < numArgs; i++) { + element = arguments[i]; + if (action == 'add') { + element.find('label.required').each(function(){ + el = $(this); + labelText = el.html(); + newLabelText = labelText + requiredHintText; + el.html(newLabelText); + }); + } + else { + /* NB IE modifies the html text when it's inserted. E.g., + * the requiredHintText becomes * + * So a replace of the text with an empty string won't work, unless + * we first convert to a regexp such as / \*<\/span>/i + * However, the remove() call is simpler anyway. + */ + element.find('span.requiredHint').remove(); + } + + } + }, showFields: function(el) {