function addSuggest(fieldName, contextId, otherParams) { //we need to add the div to the fields first... if (contextId == undefined) { contextId = 0; } if (otherParams == undefined) { otherParams = ""; } try { var addLastRequest = ""; if(typeof(setLastRequest) !== 'undefined') { addLastRequest = "&suggestLastRequest=" + setLastRequest; } var field = eval("document.entry_form." + fieldName); field.id = fieldName; var fieldDiv = document.createElement("div"); fieldDiv.id = fieldName+"_choices"; fieldDiv.className = "autocomplete"; field.parentNode.appendChild(fieldDiv); //next we're going to add the autocomplete call... //new Ajax.Autocompleter(fieldName, fieldName+"_choices", "", {parameters:'page=alcea.mod.suggest.CornerSuggest&CONTEXT='+contextId+'&suggest=1'+addLastRequest+otherParams+'&field='+fieldName, afterUpdateElement : lookupField}); jQuery("#"+fieldName).autocomplete({ source: function( request, response ) { jQuery.ajax({ url: '', data: fieldName+'='+request.term+'&page=alcea.mod.suggest.CornerSuggest&CONTEXT='+contextId+'&suggest=1'+addLastRequest+otherParams+'&field='+fieldName, dataType: "html", success: function( data ) { // if we change to jsonp above and change server, then we can just call response(items), but I will leave server alone for now. var items=[]; var lines = data.split(""); for (i = 0; i < lines.length-1; i++) { //console.log(lines[i]); var arr = lines[i].match(/.*origIndex="(\d+)">(.*)(.*)<\/span.*/); //console.log(arr[1] + " " + arr[2]); var item = { value: arr[2], label: arr[2]+arr[3] }; items.push(item); } response(items); }, error: function(xhr, error) { alert("Failure: "+xhr+" - " +error); } }); }, minLength: 1, select: function( event, ui ) { //alert( ui.item ?"Selected: " + ui.item.label :"Nothing selected, input was " + this.value); var obj = { name: fieldName, value: ui.item.value } lookupField(obj,jQuery("
- test
").get(0)); //0 index means it starts looking at bottom }, open: function() { jQuery( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); }, close: function() { jQuery( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); } }); } catch(err) { //This won't apply for View Bug alert('exception99'); } } function addLookupToDropdown(fieldName) { try { var field = eval("document.entry_form." + fieldName); var origOnchange = field.onchange; field.onchange = function(){ if (origOnchange) changeField(field); var li = document.createElement("li"); li.innerHTML = field.value; lookupField(field,li); } } catch(err) { //This won't apply for View Bug } } var keyUpLength = 0; function addLookupToString(fieldName) { try { var field = eval("document.entry_form." + fieldName); if (this === document.activeElement) { } else { return; } field.onkeyup = function() { if (field.value.length >= onKeyUpLength) { var li = document.createElement("li"); li.innerHTML = field.value; lookupField(field,li); } } } catch(err) { //This won't apply for View Bug } } function lookupField(fieldName,li) { //var field = eval("document.entry_form."+fieldName); //if (field.value.length < 4) { // return false; //} try { jQuery.ajax({ type: 'GET', url: '?page=alcea.mod.suggest.CornerSuggest&origIndex='+(li.getAttribute("origIndex"))+ '&lookup=1&field='+fieldName.name+'&'+fieldName.name+'='+escape(fieldName.value), success: function(t) { eval(t); }, error: function(xhr, textStatus, errorThrown) { //jQuery(".error-summary").html(xhr.responseText); alert('Error ' + textStatus); } }); } catch(err) { txt="There was an error on this page for lookupField.\n\n"; txt+="Error description: " + err.description + "\n\n"; txt+="Click OK to continue.\n\n"; alert(txt); } } function updateLookupField(fieldName,fieldVal) { var field = eval('document.entry_form.'+fieldName); field.value = fieldVal; } function updateLookupDropdownField(fieldName,fieldVal) { var field = eval('document.entry_form.'+fieldName); if (!field.options) { field.value=fieldVal; return; } for (var i = 0; i < field.options.length; ++i) { //alert("Matching: " + fieldVal.toLowerCase() + " - Against: " + field.options[i].value.toLowerCase()); if (field.options[i].value.toLowerCase() == fieldVal.toLowerCase()) { field.selectedIndex = i; } } }