View member feedback to this tip.
It is often important to make keyword fields dynamic so the list can change based on the values selected in other documents. To get the list of existing values, you create a lookup view sorted by that column and use @DBColumn to get the list. In Notes client, you can set the keyword option, "Allow values not in list" to let the user enter a new value. However, on the Web that setting causes the browser to change the field to a plain text field because it does not have that capability.
Many developers work around this by putting a text field next to the dialog list field, where the user can enter a new value. To do so you have to either always show the field, or refresh the form and use hide formulas to display the text field.
There is a better way. If you add an option to the list called "<New Value>" (or something similar), you can use JavaScript to do the following:
- Check whether "<New Value>" is selected.
- Prompt the user for a new value.
- Add that choice to the dialog list.
- Automatically select the new choice.
Here is how:
Add this function to the form's JavaScript header:
function NewDialogListOption (objField) {
strLabel = objField.name;
// Check whether the user is
choosing to enter a new value
if(objField.options[objField.selectedIndex].text
== "<New
Value>")
{
// Prompt for new value
var strNewValue = prompt ("Enter new "
+ strLabel + ": ", "");
if (strNewValue != null)
{
// Create a new option object
var NewOption = document.
createElement("Option");
NewOption.text = strNewValue;
// Add the new option to the list
objField.add(NewOption);
// Select the new option
objField.selectedIndex =
(objField.options.length - 1);
}
}
}
Put this code in the field's onChange event:
NewDialogListOption (this);
MEMBER FEEDBACK TO THIS TIP
The field type needs to be a listbox, not a dialog list, for it to work.
Elizabeth F.
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip exchange by member Brad Balassaitis. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.