From 2a2d87006bce9e78775ae0a9221312e9aa0e3ff0 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 3 Sep 2010 21:50:27 +0000 Subject: [PATCH] NIHVIVO-1110 Fix cancel button after validation errors on all custom form types --- .../forms/js/customFormWithAutocomplete.js | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/productMods/edit/forms/js/customFormWithAutocomplete.js b/productMods/edit/forms/js/customFormWithAutocomplete.js index f89ec1fa..93f8dacc 100644 --- a/productMods/edit/forms/js/customFormWithAutocomplete.js +++ b/productMods/edit/forms/js/customFormWithAutocomplete.js @@ -158,15 +158,6 @@ var customForm = { if (uri) { this.showAutocompleteSelection(label, uri); } - - this.cancel.unbind('click'); - this.cancel.click(function() { - // Cancel back to full view with only type selection showing - customForm.undoAutocompleteSelection(); - customForm.clearFields(customForm.fullViewOnly); - customForm.initFormFullView(); - return false; - }); }, @@ -178,14 +169,8 @@ var customForm = { var typeVal = $(this).val(); // If an autocomplete selection has been made, undo it. - // The test is not just for efficiency: undoAutocompleteSelection empties the acSelector value, - // which we don't want to do if user has manually entered a value, since he may intend to - // change the type but keep the value. If no new value has been selected, form initialization - // below will correctly empty the value anyway. - if (!customForm.acSelection.is(':hidden')) { - customForm.undoAutocompleteSelection(); - } - + customForm.undoAutocompleteSelection(); + // Reinitialize view. If no type selection in a two-step form, go back to type view; // otherwise, reinitialize full view. (!typeVal.length && customForm.formSteps > 1) ? customForm.initFormTypeView() : customForm.initFormFullView(); @@ -356,18 +341,23 @@ var customForm = { // Cancel action after making an autocomplete selection: undo autocomplete // selection (from showAutocomplete) before returning to full view. undoAutocompleteSelection: function() { - - this.acSelectorWrapper.show(); - this.hideFields(this.acSelection); - this.acSelector.val(''); - this.acUriReceiver.val(''); - this.acSelectionInfo.html(''); - this.verifyMatch.attr('href', this.verifyMatch.data('baseHref')); - - if (this.formSteps > 1) { - this.acSelection.find('label').html('Selected '); - } - + + // The test is not just for efficiency: undoAutocompleteSelection empties the acSelector value, + // which we don't want to do if user has manually entered a value, since he may intend to + // change the type but keep the value. If no new value has been selected, form initialization + // below will correctly empty the value anyway. + if (!this.acSelection.is(':hidden')) { + this.acSelectorWrapper.show(); + this.hideFields(this.acSelection); + this.acSelector.val(''); + this.acUriReceiver.val(''); + this.acSelectionInfo.html(''); + this.verifyMatch.attr('href', this.verifyMatch.data('baseHref')); + + if (this.formSteps > 1) { + this.acSelection.find('label').html('Selected '); + } + } }, // Set type uri for autocomplete, and type name for labels and button text.