Page 1 of 1

UI Help

Posted: September 9th, 2004, 2:34 pm
by byronnash
I am working on my first UI in javascript. I've got the interface mostly how I like it and it's all packaged in a function. I am having trouble getting data out of the form I made. I have some text boxes and check boxes. When I hit OK on my form it doesn't seem to be recording any of the data into my variables.

At what point do you use the onClick command to retrieve data? I guess I'm a little confused on how you harvest data from a UI once you have it built.

Tips, suggestions?

Posted: September 10th, 2004, 1:47 am
by Paul Tuersley
There are a few ways you can do this:

1. You can define some empty global script variables in the main body of the script, then use
functions you create for the onClick or onChange events to store the results in those global

Here's an example from one of my scripts:

In the main script body I defined this variable, so it could be accessed throughout the script.
(Variables defined inside a function are lost when you return out of that function)
var shotNotes = "";

In the build dialog function I had these lines:
var newNotes = my_dialog.add("edittext", [100, 260, 530, 280], "default text");
newNotes.onChange = on_shotNotes_changed;

In my version I had the shotNotes variable instead of "default text" on the first line so any
existing text automatically showed up in the text field

I also had this function which is called when that text field is changed
function on_shotNotes_changed()
shotNotes = this.text;

This method can be especially useful if you want to check the user has entered something valid
(i.e numbers into a text field) while the dialog is still open.

2. The other way is just to grab all the information you need when the dialog is closed (instead of
continually updating your global variables every time a change is made). I don't have an example
of this handy right now, but I think you would put the lines where you'd store the results in your
global variables after the ";" bit of your build dialog function.

Alternatively, you could create an array at that point containing all the information gathered by
the dialog, then return that array out of the function.

You might also want to check out my CreateLinkedEffects, SearchEffects and ShiftSelectedLayers
scripts for some examples.

Paul T

Posted: September 10th, 2004, 9:56 am
by byronnash
Thanks Paul. I didn't have anything after the show(). I am just trying to get the values after the user closes the window.

This forum is a big help...

Posted: September 14th, 2004, 10:40 am
by byronnash
I am about to the getting stuck part of this script.

It's going to be a function in the dialog script I've been working on. It's designed to read from a text "database" file. The file is simple, each line contains this:

Client Name,Project 1, Project 2, Project 3

My script generates a set of radio buttons for the available clients. Then I want it to dynamically generate the project list for the currently selected client. The client part works, and I'm getting close to the projects part now. It creates buttons for each set of projects on top of each other now. I guess I'm not understanding how to use the onClick() functions.

Posted: September 15th, 2004, 1:07 pm
by Paul Tuersley
You're right, it looks like onClick() is the culprit.

It seems that the line in the addProjectButton function
newButton.onClick = onProjectChange(newButton.clientID)
is actually calling the onProjectChange function instead of just defining the onClick behaviour.

I changed it to
newButton.onClick = onProjectChange;
and changed the first two lines of the onProjectChange function to
function onProjectChange() {

Paul T

Posted: September 15th, 2004, 2:23 pm
by byronnash
I don't know that I would have figured that one out Paul, thanks.

It seems to be updating on the click now. I have a new problem that's stumping me. Each time the user clicks a client in the top panel, it updates the panel with a new list of projects. It seems like it's loading the radio buttons on top of each other. I'm trying to figure out a way to clear out the previous contents of the panel. Is there a way to do this easily? I put a dlg.Proj.visible = false line right before it generates the project radio buttons. I was hoping it would hide everything it made before generating new ones but it doesn't seem to be working.

Anyone know how to handle this?

Posted: September 15th, 2004, 4:17 pm
by Paul Tuersley
byronnash wrote:I don't know that I would have figured that one out Paul, thanks.

The clue to the onClick problem was the distance between the client buttons. It pointed to the button_top/bottom values being changed in the onProjectChange function. Then I used some alerts to confirm it. i.e
alert("Loop " + j + " Button Top = " + button_top);
alert("Why am I in the onProjectChange function?");

byronnash wrote:It seems to be updating on the click now. I have a new problem that's stumping me.
I had noticed that you aren't storing the buttons:
rbutton = addProjectButton(dlg.ClientPnl,[button_left,button_top,button_right,button_bottom],sClient);
It appears "rbutton" will just get replaced on each iteration of the loop.

Maybe if you had a couple of arrays to store the client/project buttons, you could just reuse them by renaming/turning invisible when you want them to change.

It'd be useful if you could put more comments in the script. I've been having some trouble following exactly what's going on (i.e what some of the variables are used for, how the client/project data is stored, what the getProjectList function is doing)

Paul T