[jala-dev] Re: AW: preselecting a jala.Form.SelectComponent

  • From: <tobias.schaefer@xxxxxx>
  • To: <jala-dev@xxxxxxxxxxxxx>
  • Date: Fri, 4 May 2007 15:21:18 +0200

hi stefan

thanks for the clarification.

what i'd like to achieve right now, though, is the following:

i have a select element which displays all available locales (retrieved via 
java.util.Locale.getAvailableLocales) as option elements in alphabetical order.

in the initial state (ie. when creating a new object which should have the 
language property) i'd like to show the locale to be (heuristically) considered 
the most useful one (aka the default) as the selected one (e.g. "en").

of course, after saving the form data the selected one is displayed.

thus, i need "en" to be selected when there is no property set, yet; and 
afterwards i need the chosen locale which is then the property value.

obviously, i need a mixture of both worlds, don't i?
how would i do this?

ciao,
tobi


stefan.pollach@xxxxxx wrote:
> Hi Tobi,
> 
> the select component preselects the option whose value matches the
> value of the data object's field or the value returned by the getter
> function (if you have set one). There is no config option to override
> this.   
> 
> An example using the current API:
> 
> var dataObj = new HopObject();
> dataObj.zipcode = "1060";
> var form = new jala.Form("testform");
> var zipcode = new jala.Form.SelectComponent();
> zipcode.setOptions([["1040", "1040"], ["1050", "1050"], ["1060",
> "1060"]]); form.addComponent(zipcode); form.setDataObj(dataObj);  
> 
> This would preselect "1060" in the dropdown.
> 
> Without a data object, using a getter function it would look like
> this: 
> 
> var form = new jala.Form("testform");
> var zipcode = new jala.Form.SelectComponent();
> zipcode.setOptions([["1040", "1040"], ["1050", "1050"], ["1060",
> "1060"]]);  
> zipcode.setGetter(function() {  return "1060";        });
> form.addComponent(zipcode);
> 
> lg,
> Stefan

Other related posts: