Dynamic Select List Allowed Values

Howdy Folks,

I am trying to allow end users to select their username. The usernames are generated from a rule library, and displayed in a select form element. I am doing this by having the allowedValues call the rule that generates the possible names directly. The rule returns a list of valid names. The problem I am currently having, is that if the page reloads or refreshes, then the allowedValues calls the rule again. Some of the username choices involve random numbers, so it is possible (and very likely), that separate calls to the rule will generate different potential values. So what is now happening, is that when a user selects the value, the page reloads, and the end user sees an error that looks like this:

( ) - Warning: Selected value for field 'Select a Valid User Name' does not match any of the allowed values.

The reason I am reloading the page, is that I am also trying to show the user what their email address will look like with the new value. So I have a different form element that is loading is value dynamically, and referencing the select form element. This mostly works, but the warning above is unacceptable.

Is there a way I can load the dynamically created list only once, the first time the form is viewed, and not load it again every time the page refreshes?

Another thing I tried to do (but didn't have luck with, so I sorta gave up on it) was to use the onChange of the select to change the value of email display field. This way the page never reloads and I don't have to deal with that issue. I'm thinking the onChange might actually work, but I would need to execute javascript or something, and not just use an express <set/> command to set the value of the field name that displays the email text.

Does anyone have advice on how to make the values only load once? Or how to change the value on the onChange event?

Thanks!

Jim

[1936 byte] By [JimBearda] at [2007-11-26 20:49:42]
# 1
Generate the values as part of a variable - either on the form as a defvar or in the workflow - and then just reference that variable as the allowed values - that should work - let me know if you need an example.Mike KlugAegis USA
mklugACNa at 2007-7-10 2:13:47 > top of Java-index,Web & Directory Servers,Directory Servers...
# 2

Mike,

Thanks for the feedback. I actually did try that eventually. I created a variable in the form, and initialized that variable to the list of possible values. Then I referenced the variable in the 'allowedValues' of the select form item. At that point in time I still had the select box set as an action, so it would reload the page, hoping to reload the value in the email display field. This still did not work. Each time the action fired off, the variable was re-initializing itself. I eventually tried to put in a check, so it would not re-initialize itself if it had already been initialized. That caused a syslog error.

I ended up solving the problem using javascript. I changed the field that reported the potential email address to an html element. Then for the html attribute I made a div with an ID. I then set a line of javascript into the onChange attribute of the select form element. This worked when ever the select form value changed. I then added the same line of javascript to the onLoad attribute of the jsp pages body element. This worked for loading the page.

This solved the problem of the page reloading and the select getting new values. That still happens if you actually reload the page, but all the form elements work without the reload now.

Thanks!

Jim

JimBearda at 2007-7-10 2:13:47 > top of Java-index,Web & Directory Servers,Directory Servers...
# 3
Stupid answer, but have you tried using a Field with a Default element? The Default element will only be set if the Field value is null, which should only be the first time.
vinhanta at 2007-7-10 2:13:47 > top of Java-index,Web & Directory Servers,Directory Servers...
# 4
Hi,can you please share the example code for this?Thanks in advance.
rusmanpurkara at 2007-7-10 2:13:47 > top of Java-index,Web & Directory Servers,Directory Servers...
# 5
Hi,I think you managed to solve the problem.Can you please tell me what code (Javascript) we need to insert for onChange property.I am facing the same problem, can you please post some hints.Thanks
dortmund_developera at 2007-7-10 2:13:47 > top of Java-index,Web & Directory Servers,Directory Servers...
# 6
The javascript on the onChange of the Select field looks like this:document.getElementById('EmailDisplay').innerHTML = "Your email address will be " + document.mainform.UnameSelect.value + "@uoregon.edu";
JimBearda at 2007-7-10 2:13:47 > top of Java-index,Web & Directory Servers,Directory Servers...