for example:
/// Fired when the page is loaded
Method onloadHandler() [ Language = javascript ]
{
var country = zenPage.getComponentById("country");
country.setValue("USA");
}
-Jill
The onloadHandler is just automatically called whenever the page is loaded.
I misread your initial post- if you are using a datacombo which gets values from a db, there is not a way to programmatically add to it-
From using zen:
A <dataCombo> is a specialized type of <combobox> that presents the user with a list of options obtained at runtime via an SQL query. Unlike <combobox>, <dataCombo> does not allow you to specify <option> elements or to set styles for individual options in the list. This is because <dataCombo> uses a query to obtain a dynamic list of options. There are no statically defined options in a <dataCombo>, so there are no <option> elements.
Therefore, what you may want to do is use a normal combo box, and manually get the information out of the database and then add to it; if it's a list then by adding to both the displayList and the valueList;
If it's a combo box, then by making additional option elements.
See using zen- the Lists chapter for reference.
The:
country.setValue("USA");
is just shorthand for: country.setProperty('value', 'USA');
I think I see the issue.
Instead of
.. d %page.%SetValueById.setValue("country",Name)
Try
.. d %page.%SetValueById("country",Name)
%SetValueById is the Method itself. It does not contain an additional setValue method.
Also, since you are on the server side in an instance method this should work, too:
.. d ..%SetValueById("country",Name)
Randy L Stewart
Sales Engineer
InterSystems Corporation
Randy....@intersystems.com
214-551-5781
Earlier I failed to realize you were working with a listBox rather than just a text field. Below are two examples that should allow you to add listBox values in either the %OnAfterCreatePage() method or in the onloadHandler() method depending on which you would rather use. The examples assume a listBox defined in the XData like this:
<listBox id="country" label="country" onchange="zenPage.notifyOnChange(zenThis);" listWidth="240px"/>
I won't worry about your loop to get the values for the box because that looks fine. I will just put a comment as a placeholder for your loop. But when you get to the point where you want to add to the list box here is how it goes:
Method %OnAfterCreatePage() As %Status
{
s tOptionCount=0
s tListBox=%page.%GetComponentById("country")
// Add a blank option at the top if you want it
s tOption=##class(%ZEN.Auxiliary.option).%New()
s tOption.value=""
s tOption.text=""
d %page.%AddChild(tOption)
d tListBox.options.Insert(tOption)
// Your loop to get values
// For each value
s tOptionCount=$increment(tOptionCount)
s tOption=##class(%ZEN.Auxiliary.option).%New()
s tOption.value=tOptionCount
s tOption.text=Name
d %page.%AddChild(tOption)
d tListBox.options.Insert(tOption)
// End loop
}
You could also use the onloadHandler method. The code is simpler but then you would have to figure out how to get your values from the server.
Method onloadHandler() [ Language = javascript ]
{
var c=zenPage.getComponentById('country');
c.appendOption('',''); // blank option
c.appendOption(1,'CountryOne');
c.appendOption(2,'CountryTwo');
}
I included the notifyOnChange() for testing
Method notifyOnChange(comp) [ Language = javascript ]
{
alert(comp.value+' '+comp.text);
}
Since you are retrieving the option values from the server it looks like the %OnAfterCreatePage method is the way to go here.
I hope I was more thorough in handling your issue this time.
Best regards!
Randy L Stewart
Sales Engineer
InterSystems Corporation
Randy....@intersystems.com
214-551-5781
1) The examples in Zen Application Programming, one under the heading "Zen Properties on Client and Server" and the other under the heading of "Defining Page Contents Programmatically". These examples showed how to work with %page objects on the server side, including the need to create new objects and add them to the %page.
2) Reading the code of the %ZEN.Component.listBox. It was in the %SetDefaultValues method that I discovered the options.Insert method. It also showed adding new objects to the %page.
With a little experimentation these were cobbled together into a working example.
The Zen documentation is very good. Every once in a while an examples is found to be needed that was not thought of at first. I will make the proper request to get this one added for future reference.
Thanks.
Randy L Stewart
Sales Engineer
InterSystems Corporation