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.

This commit is contained in:
rjy7 2010-04-12 23:49:23 +00:00
parent a8b39bf005
commit 888607cf39

View file

@ -53,6 +53,7 @@ var customForm = {
COMBINED: 3 COMBINED: 3
}, },
onLoad: function() { onLoad: function() {
this.initObjects(); this.initObjects();
@ -76,7 +77,7 @@ var customForm = {
this.existingSelect = this.existing.children('select'); this.existingSelect = this.existing.children('select');
this.addNew = $('.new'); this.addNew = $('.new');
this.entry = $('.entry'); 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.cancel = this.form.find('.cancel');
this.requiredHints = this.form.find('.requiredHint'); this.requiredHints = this.form.find('.requiredHint');
@ -289,6 +290,8 @@ var customForm = {
// Use when the non-Javascript version should not show the required hint, // 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 // 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). // 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' // Arguments: action = 'add' or 'remove'
// Varargs: element(s) // Varargs: element(s)
toggleRequiredHints: function(action /* elements */) { toggleRequiredHints: function(action /* elements */) {
@ -296,16 +299,33 @@ var customForm = {
var labelText, var labelText,
newLabelText, newLabelText,
requiredHintText = '<span class="requiredHint"> *</span>', requiredHintText = '<span class="requiredHint"> *</span>',
numArgs = arguments.length; numArgs = arguments.length,
element,
el;
for (var i = 1; i < numArgs; i++) { for (var i = 1; i < numArgs; i++) {
arguments[i].find('label.required').each(function() { element = arguments[i];
labelText = $(this).html(); if (action == 'add') {
newLabelText = action == 'add' ? labelText + requiredHintText : element.find('label.required').each(function(){
labelText.replace(requiredHintText, ''); el = $(this);
$(this).html(newLabelText); 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 <SPAN class=requiredHint> *</SPAN>
* So a replace of the text with an empty string won't work, unless
* we first convert to a regexp such as /<span class="?requiredHint"?> \*<\/span>/i
* However, the remove() call is simpler anyway.
*/
element.find('span.requiredHint').remove();
}
}
}, },
showFields: function(el) { showFields: function(el) {