There is currently a bug in suggest boxes. You can set the value with setValue(), but it doesn't select one of the options.
I have created two workaround functions that you should use in place of setValue() and setText() with suggest boxes:
Code: Select all//function to use in place of setText() with suggest boxes:
// if the ID of the suggest box is "selectUser" and its SQL query is:
// SELECT USR_UID, USR_USERNAME FROM USERS
// then: selectOptionText('selectUser', 'admin');
function selectOptionText(suggestId, optionText) {
var aOptions = getFieldById(suggestId).executeQuery();
for (var i in aOptions) {
if (aOptions[i].text.search(optionText) != -1) {
$("[id='form["+suggestId+"_label]']").val( aOptions[i].text );
$("[id='form["+suggestId+"]']").val( aOptions[i].value );
return;
}
}
//no match found in list of options so use setText():
$("#"+suggestId).setText(optionText);
}
//function to use in place of setValue() with suggest boxes:
// if the ID of the suggest box is "selectUser" and its SQL query is:
// SELECT USR_UID, USR_USERNAME FROM USERS
// then: selectOptionValue("selectUser", "00000000000000000000000000000001");
function selectOptionValue(suggestId, optionValue) {
var aOptions = getFieldById(suggestId).executeQuery();
for (var i in aOptions) {
if (aOptions[i].value.search(optionValue) != -1) {
$("[id='form["+suggestId+"_label]']").val( aOptions[i].text );
$("[id='form["+suggestId+"]']").val( aOptions[i].value );
break;
}
}
//no match found in list of options so use setValue():
$("#"+suggestId).setValue(optionValue);
}
Here is a sample DynaForm to demonstrate its use:
(2.7 KiB) Downloaded 331 times