Manage Learn to apply best practices and optimize your operations.

Create dynamic keyword fields

Make keyword fields dynamic so the list can change based on the values selected in other documents.

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:

  1. Check whether "<New Value>" is selected.
  2. Prompt the user for a new value.
  3. Add that choice to the dialog list.
  4. 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.

Dig Deeper on JavaScript for Lotus Notes Domino

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close