How does one set "" as a combobox default value?

  • I have a combo box that takes values from a document, but it also has legacy data that is not on the document, because it used to be “allow values no in list”. I include the document values with a selecItems, and the custom value with selectItem. As long as I use getItemValueString() to set the selectItem everything works fine.

  • Except if there is no value, so getItemValueString() returns a null, then it won’t set that value as selected, even when the value= attribute on the comboBox is set to the getItemValueString() value. Instead there is no selection, and the browser defaults to showing the first entry in the list. This wouldn’t be a problem, except Domino then saves that first value on submit, even when there is not and never has been an actual value in the field.

  • Does anyone know how to work around this?

Thanks for your time…

Subject: What about computing the default value?

I did not totally follow your situation but you can calculate the default value any way you want and then return the “” as the default value.

On my forms I usually display “No Choices” with an actual value of “” and I do that through server-side Javascript methods.

Subject: Clarification?

  • Duh. I can put the source here and remove all ambiguity. Here’s a go:

<xp:comboBox id=“someField” value=“#{doc.field}”>

<xp:this.defaultValue><!--[CDATA[#{javascript:

	doc.getItemValueString('field');

}]].</xp:this.defaultValue>

<xp:selectItems>

	<xp:this.value><![CDATA[#{javascript:

		var items=@DbLookup(@DbName(), "Lookup", "fieldKeys", 2);

		(items==null ? "" : items);

	}]]></xp:this.value>

</xp:selectItems>

<xp:selectItem itemLabel="#{javascript:doc.getItemValueString('field')}" />

</xp:comboBox>

The document contains legacy data that may or may not be in fieldKeys. This is an attempt to web-enable the application with that legacy data. Adding all values from field not in fieldKeys is not a viable option.

Whether doc has a value from fieldKeys or not, it shows that value selected, because the independent selectItem ensures that value is valid on that page.

BUT if doc.field is “”, even though that value is present (via the selectItem) and should be the default, it is not selected. Instead the first value from fieldKeys is displayed in the combo box.

Page source shows no selected attribute on any combo box value at initial page load, when doc.field = “”, but when submitted, because the first value in fieldKeys is displayed, that value replaces the “” and destroys data.

Is there a way to make the above work?

Thanks for your time…

Subject: for example

maybe that would work?

if value <> “” Then

getItemValueString()

Else

setfield(“value”,“”)

getItemValueString()

end if