NIHVIVO-647 More on publication form autocomplete

This commit is contained in:
rjy7 2010-07-09 20:21:11 +00:00
parent 09d99757c6
commit 378d4c8fa3
2 changed files with 20 additions and 12 deletions

View file

@ -180,7 +180,7 @@ var addAuthorForm = {
data: request, data: request,
complete: function(xhr) { complete: function(xhr) {
// Not sure why, but we need an explicit json parse here. jQuery // Not sure why, but we need an explicit json parse here. jQuery
// should parse the response text and return an json object. // should parse the response text and return a json object.
var results = jQuery.parseJSON(xhr.responseText); var results = jQuery.parseJSON(xhr.responseText);
addAuthorForm.acCache[request.term] = results; addAuthorForm.acCache[request.term] = results;
response(results); response(results);

View file

@ -86,15 +86,18 @@ var customForm = {
bindEventListeners: function() { bindEventListeners: function() {
this.typeSelector.change(function() { this.typeSelector.change(function() {
if ($(this).val().length) { var typeVal = $(this).val();
// Set the type of individual that the autocomplete will search for.
// We do this even if typeVal is empty, to clear out a previous value.
customForm.resetAutocomplete(typeVal);
if (typeVal.length) {
customForm.labelFieldLabel.html(customForm.getSelectedTypeName() + ' ' + customForm.baseLabelText); customForm.labelFieldLabel.html(customForm.getSelectedTypeName() + ' ' + customForm.baseLabelText);
customForm.initFormFullView(); customForm.initFormFullView();
// Set the type of individual that the autocomplete will search for } else {
customForm.setAcUrl($(this).val()); // If no selection, go back to type view. This prevents problems like trying to run autocomplete
console.log("ac url = " + customForm.acUrl); // or submitting form without a type selection.
} customForm.initFormTypeView();
// do we need else case? i.e. if user has set back to "select one", we should undo }
// above settings? Will it matter? they can't proceed till they've made a new selection.
}); });
}, },
@ -119,7 +122,7 @@ var customForm = {
data: request, data: request,
complete: function(xhr) { complete: function(xhr) {
// Not sure why, but we need an explicit json parse here. jQuery // Not sure why, but we need an explicit json parse here. jQuery
// should parse the response text and return an json object. // should parse the response text and return a json object.
var results = jQuery.parseJSON(xhr.responseText); var results = jQuery.parseJSON(xhr.responseText);
customForm.acCache[request.term] = results; customForm.acCache[request.term] = results;
response(results); response(results);
@ -135,10 +138,15 @@ var customForm = {
}, },
// Append the type parameter to the base autocomplete url // Reset some autocomplete values after type is changed
setAcUrl: function(typeVal) { resetAutocomplete: function(typeVal) {
// Append the type parameter to the base autocomplete url
var glue = this.baseAcUrl.indexOf('?') > -1 ? '&' : '?'; var glue = this.baseAcUrl.indexOf('?') > -1 ? '&' : '?';
this.acUrl = this.baseAcUrl + glue + 'type=' + typeVal; this.acUrl = this.baseAcUrl + glue + 'type=' + typeVal;
// Flush autocomplete cache when type is reset, since the cached values
// are relevant only to the previous type.
this.acCache = {};
}, },
showAutocompleteSelection: function(ui) { showAutocompleteSelection: function(ui) {