Subscribe Bookmark RSS Feed

Forcing ENTER with TextEditBox and ComboBox

Phil_Brown

Super User

Joined:

Mar 20, 2012

Is there a way to force a "click" or the ENTER key on TextEditBox and ComboBox?

PDB
1 ACCEPTED SOLUTION

Accepted Solutions
pmroz

Super User

Joined:

Jun 23, 2011

Solution

If I have a complex expression for a particular object I'll put it into a named expression and call it by the name.  If I want to perform the actions separately I just reference the expression.  

 

my_expr = expr(
	txt1 = teb1 << get text();
	teb2 << set text("You entered: " || txt1);
);

nw = new window("Test",
	teb1 = text edit box("", << set width(200),
		<< set script(my_expr)
	),
	teb2 = text edit box("", << set width(200)),
	bb = button box("OK",
		nw << close window;
	)
);
8 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

I am not sure I completly understand your request.  However, let me see if I can add some light on it, and if I am missing the target then you might be able to add some specifics.

 

Text Edit Box() does not have an action where you can do something based upon something changing in the box.  (i.e. tebox << on change(<script>)).  A defined script or function for Text Edit Box() requires the user to press the Enter key for the script or function to run.

 

A combo box automatically runs a specified script or function, whenever a new selection is made.  If a text edit box() has been changed, but no Enter key has been specified, and then a a combo box is clicked on, it will run the text edit box().

 

Does this help?

Jim
pmroz

Super User

Joined:

Jun 23, 2011

This example might come a little closer.  If you set focus on the first text edit box, and then tab or mouse out of it, the action will run populating the second text edit box.

 

nw = new window("Test",
	teb1 = text edit box("", << set width(200),
		<< set script(
		txt1 = teb1 << get text();
		teb2 << set text("You entered: " || txt1);)
	),
	teb2 = text edit box("", << set width(200)),
	bb = button box("OK",
		nw << close window;
	)
);
Phil_Brown

Super User

Joined:

Mar 20, 2012

Good point. See my recent reply to @txnelson

 

The key factor is that I'd like to trigger the object's script WITHOUT user interaction. For instance, the case where a user doens't want to change anything (but we still need the underlying functions to be triggered).

PDB
Phil_Brown

Super User

Joined:

Mar 20, 2012

I should have mentioned... I'm trying to force the execution of the associated object functions. (i.e. set by: obj << setFunction(). Some objects like ButtonBox, you can do button << click(). Others like ComboBox, you can do: obj << set( 1, runScript(1) ). There doesn't seem to be an equivalent message for Text Edit Box and ListBox.
PDB
pmroz

Super User

Joined:

Jun 23, 2011

Solution

If I have a complex expression for a particular object I'll put it into a named expression and call it by the name.  If I want to perform the actions separately I just reference the expression.  

 

my_expr = expr(
	txt1 = teb1 << get text();
	teb2 << set text("You entered: " || txt1);
);

nw = new window("Test",
	teb1 = text edit box("", << set width(200),
		<< set script(my_expr)
	),
	teb2 = text edit box("", << set width(200)),
	bb = button box("OK",
		nw << close window;
	)
);
vince_faller

Super User

Joined:

Mar 17, 2015

I sometimes do a.  

click = nameexpr(obj << Get Function);

click()

 

the nameexpr is just a safety net because depending on the complexity there are sometimes issues with it.  

Phil_Brown

Super User

Joined:

Mar 20, 2012

Yes indeed. Get Function... I've had some trouble getting this to work consistently.

One troublesome Displaybox to hack is PopupBox. Doesn't seem there's away of indirectly triggering those menu scripts
PDB
vince_faller

Super User

Joined:

Mar 17, 2015

If you don't have to build the functions dynamically Then I would say that you just don't use anonymous funcitons (basically the same idea as peter).  

 

Names Default to here(1);
f = function({self}, {},
print("stuff")
);

somebox << Set Function(f);

 

then just call f when f(somebox) when you want to run it.