There are several ways to solve this. One option would be to use a dropdown list constraint - these already automatically have an autocomplete capability in DashBoard:
Arthur A. Aaronson
Buford B. Buckthorn
Carl C. Carlson
Dianna D. Dickenson
Erica E. Ellis
var newConstraint = params.createIntChoiceConstraint(["Nothing"]);
params.replaceConstraint('Constraint_From_XML', newConstraint);
function getXML(file)
{
//for testing, I am replacing the file XML with hard-coded XML. Remove these lines for loading an actual file
file = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
'\n' +
' \n' +
' \n' +
' \n' +
' \n' +
' \n' +
''
return ogscript.parseXML(file); //Parse the XML
}
function loadData(dataFile)
{
var xmlDocument = getXML(dataFile); //Parse the XML
var nodeList = xmlDocument.getElementsByTagName(“item”); //Get the tags we want to include in the constraint
var constraintData = ; //Placeholder for the new constraint data
for (var i = 0; i < nodeList.getLength(); i++) //Loop through each tag we found
{
var node = nodeList.item(i); //Get the node
var takeID = parseInt(node.getAttribute(“takeid”));
var name = node.getAttribute(“name”);
constraintData.push({“key”: takeID, “value”: name}); //Push the key/value pair
}
if (constraintData.length == 0) //Placeholder if we don’t have anything (OPTIONAL)
{
constraintData.push({“key”: 0, “value”: “Nothing”});
}
var constraint = params.createIntChoiceConstraint(constraintData); //Create the constraint
params.replaceConstraint(‘Constraint_From_XML’, constraint); //Replace the constraint
}
ogscript.rename('selected-take', this.getValue());
loadData('data.xml');
You can also provide the dropdown list as a search field and show your whole table:
Arthur A. Aaronson
Buford B. Buckthorn
Carl C. Carlson
Dianna D. Dickenson
Erica E. Ellis
Arthur A. Aaronson
Buford B. Buckthorn
Carl C. Carlson
Dianna D. Dickenson
Erica E. Ellis
all-take-ids
all-names
var newConstraint = params.createIntChoiceConstraint(["Nothing"]);
params.replaceConstraint('Constraint_From_XML', newConstraint);
function getXML(file)
{
//for testing, I am replacing the file XML with hard-coded XML. Remove these lines for loading an actual file
file = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
'\n' +
' \n' +
' \n' +
' \n' +
' \n' +
' \n' +
''
return ogscript.parseXML(file); //Parse the XML
}
function loadData(dataFile)
{
var xmlDocument = getXML(dataFile); //Parse the XML
var nodeList = xmlDocument.getElementsByTagName(“item”); //Get the tags we want to include in the constraint
var allTakeIDs = ;
var allNames = ;
var constraintData = ; //Placeholder for the new constraint data
for (var i = 0; i < nodeList.getLength(); i++) //Loop through each tag we found
{
var node = nodeList.item(i); //Get the node
var takeID = parseInt(node.getAttribute(“takeid”));
var name = node.getAttribute(“name”);
constraintData.push({“key”: takeID, “value”: name}); //Push the key/value pair
allTakeIDs.push(takeID);
allNames.push(name);
}
if (constraintData.length == 0) //Placeholder if we don’t have anything (OPTIONAL)
{
constraintData.push({“key”: 0, “value”: “Nothing”});
allTakeIDs.push(0);
allNames.push(‘’);
}
var constraint = params.createIntChoiceConstraint(constraintData); //Create the constraint
params.replaceConstraint(‘Constraint_From_XML’, constraint); //Replace the constraint
params.setAllValues(‘all-take-ids’, allTakeIDs);
params.setAllValues(‘all-names’, allNames);
}
var index = this.getConstraint().getChoice(this.getValue());
params.setValue('table', 0, index);
loadData('data.xml');
40
Lastly, you could do a search box that looks for a full or partial match as the user types:
Arthur A. Aaronson
Buford B. Buckthorn
Carl C. Carlson
Dianna D. Dickenson
Erica E. Ellis
all-take-ids
all-names
function getXML(file)
{
//for testing, I am replacing the file XML with hard-coded XML. Remove these lines for loading an actual file
file = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
'\n' +
' \n' +
' \n' +
' \n' +
' \n' +
' \n' +
''
return ogscript.parseXML(file); //Parse the XML
}
function loadData(dataFile)
{
var xmlDocument = getXML(dataFile); //Parse the XML
var nodeList = xmlDocument.getElementsByTagName(“item”); //Get the tags we want to include in the constraint
var allTakeIDs = ;
var allNames = ;
for (var i = 0; i < nodeList.getLength(); i++) //Loop through each tag we found
{
var node = nodeList.item(i); //Get the node
var takeID = parseInt(node.getAttribute(“takeid”));
var name = node.getAttribute(“name”);
allTakeIDs.push(takeID);
allNames.push(name);
}
if (allNames.length == 0) //Placeholder if we don’t have anything (OPTIONAL)
{
allTakeIDs.push(0);
allNames.push(‘’);
}
params.setAllValues(‘all-take-ids’, allTakeIDs);
params.setAllValues(‘all-names’, allNames);
}
function search(partial)
{
partial = partial.toLowerCase();
var allNames = params.getAllValues(‘all-names’);
//LOOK FOR AN EXACT MATCH
for (var i = 0; i < allNames.length; i++)
{
if (partial == allNames[i].toLowerCase())
{
return i;
}
}
//LOOK FOR AN “STARTS WITH” MATCH
for (var i = 0; i < allNames.length; i++)
{
if (allNames[i].toLowerCase().indexOf(partial) == 0)
{
return i;
}
}
//LOOK FOR AN “ANYWHERE” MATCH
for (var i = 0; i < allNames.length; i++)
{
if (allNames[i].toLowerCase().indexOf(partial) >= 0)
{
return i;
}
}
return -1;
}
function findName(partial)
{
var selectedIndex = search(partial);
params.setValue(‘table’, 0, selectedIndex);
}
function clearSearch()
{
params.setValue(‘search’, 0, ‘’);
}
true
if (this.getValue() != '')
{
findName(this.getValue());
}
loadData('data.xml');
40