Page 1 of 1

How can I detect OK/Cancel button ?

Posted: September 25th, 2008, 7:34 am
by blies
Hi everybody.
Maybe my question have a simple answer, but I don't know how to detect an Ok/Cancel button press.

I create a dialog in this way

Code: Select all

res =
"dialog { alignChildren: 'fill', text: 'xxxxx', \
...
buttons: Group { orientation: 'row', alignment: 'right', \
okBtn: Button { text:'OK', properties:{name:'ok'} }, \
cancelBtn: Button { text:'Cancel', properties:{name:'cancel'} } \
} \
}";
win = new Window (res);
win.center(); win.show();
(I omit the other fields) .. and next ? :(

Thanks in advance ;)

Re: How can I detect OK/Cancel button ?

Posted: September 25th, 2008, 8:16 am
by Dan Ebberts
You just need to set up a function to handle the click and then link the button to it like this:


function okClick(){
(your function here)
}
.
.
.
.
win = new Window (res);
win.buttons.okBtn.onClick = okClick;


Dan

Re: How can I detect OK/Cancel button ?

Posted: September 25th, 2008, 8:28 am
by blies
Great! Great! Great!
Thanks! Thanks! Thanks!

Re: How can I detect OK/Cancel button ?

Posted: September 26th, 2008, 6:34 am
by blies
Dan, sorry for the new question.
Obviously when I call okClick, inside the function I loose every var/obj that I create before, right ?

How can I pass that parameters ?

I tried
win.buttons.okBtn.onClick = okClick(myComp,win);
.. but I got undefined errors

Why ?

Re: How can I detect OK/Cancel button ?

Posted: September 26th, 2008, 7:48 am
by Dan Ebberts
You can create variables and objects that are outside the scope of all functions and you can access those anywhere. Other than that, you can use "this" and "parent" to get at attributes of the panel objects. In your case,

"this" references the button

this.parent references the buttons group

this.parent.parent references the dialog

Dan

Re: How can I detect OK/Cancel button ?

Posted: September 26th, 2008, 7:54 am
by blies
Ok .. and I don't know why I loose myComp that is set at the begin of the script :(