Page 1 of 2

How to detect changed text in a field?

Posted: Tue May 06, 2008 9:27 am
by ale870
Hello,

I need to detect (event) when the text in a field is changed, but I cannot find any event like "on changeField" or similar.

Is there any way to do this?

Thank you!

Posted: Tue May 06, 2008 10:00 am
by Klaus
Hi ale870,

check "closefield" in the docs!
-> Sent to a field when the focus is being removed from that field and the field's content has changed.


Best

Klaus

Posted: Tue May 06, 2008 10:49 am
by BvG
Most likely you do not really want the closeField messsage, but you want to vote for bug 5888

Posted: Tue May 06, 2008 11:13 am
by gyroscope
Apologies for slightly diverting your post, ale870, hope that's OK.

BvG, it's not obvious to me how I vote for suggestions/bug fixes on that site (possibly right under my nose though...); maybe I have to create a new account, sign in and info appears then?

Posted: Tue May 06, 2008 11:51 am
by BvG
Of course you have to create an account. That's the official revolution bug database, and i think your account email has to match the one you supplied when you bought your rev version.

Posted: Tue May 06, 2008 11:58 am
by gyroscope
Sorry for asking something obvious, BvG! Yes, it makes (er, obvious) sense what you say.

I'll certainly be setting up an account and voting for bug 5888.

Thank you.

:)

Posted: Tue May 06, 2008 12:06 pm
by Klaus
BvG wrote:Most likely you do not really want the closeField messsage, but you want to vote for bug 5888
...and until this has been implemented you WILL likely want to use "closefield" :-D

Posted: Tue May 06, 2008 12:32 pm
by ale870
Thank you!
I'm very angry discovering there is not yet a message like "textChanged" (basic features in any GUI based application).
However, thank you again to you for the information!
I will try to use "closeField" (I will check and study how to use it).

Thank you! :D

Posted: Tue May 06, 2008 1:01 pm
by Klaus
Please calm down!

Maybe "selectionchanged" will help you chill... ;-)

Posted: Tue May 06, 2008 5:12 pm
by ale870
Ok, Ok :D
I will check "selectionchanged" then I will be angry later... :D

Posted: Tue May 06, 2008 5:18 pm
by Klaus
ale870 wrote:Ok, Ok :D
I will check "selectionchanged" then I will be angry later... :D
OK, deal! :-D

Posted: Tue May 06, 2008 7:47 pm
by FourthWorld
While the requested message would add a novel convenience to my my work, I can't say its absence would be cause for "anger", or really anything beyond the most mild annoyance, if even that.

After building apps in a variety of languages without such a message for 20 years, I'm confident al870 can find a suitable solution with acceptable effort if only he would take a moment to explain what it is he actually wants to do.

Posted: Tue May 06, 2008 9:18 pm
by ale870
Hello,

of course, I can find a worksround (no problem), but if that message was existing, then it could simplify my job :wink:

Since I'm new to Rev Studio, can you give me an hint to solve this problem (I say that I have a workaround, but I don't like it, so you could give me a better solution).

Basically, I have a small rev program with three buttons and one field (this is the field where I wnated to use that message!).

LAYOUT:
[BUTTON 1] [BUTTON 2] [BUTTON 3]

[
myField
]

Well, at the first time I made a different http request (GET) on every button and I putted the result in the field (not as html, since I'm working getting xml data, so I used plain text).

Well, now I decided to clean up the field as first operation. I didn't want to edit every button to change the code....

OLD BUTTON CODE:

Code: Select all

put url "http://........." into field "myField"
NEW CODE COULD BE:

Code: Select all

put empty into field "myField"
put url "http://........." into field "myField"
Well, since I didn't want to edit every button, I decided to use the (non existing :cry: message) to "intercept" myField modification (caused by "put url ......") and, in such event (inside the field self), delete the field and then "propagate" the event to receive new value. Here how that code could be (inside "myField"):

Code: Select all

on changedField
  put empty into field "myField"
  pass changedField
end changedField
In this way I could simply modify an event, instead all buttons.

Even if it seems an excercise, I think it could be very interesting!

Thank you for your help!

Posted: Tue May 06, 2008 10:14 pm
by Nonsanity
The CloseField event is mainly to detect when the USER has made a change to a field. If the code of the project is changing the field, then the code of the project should know that the field is changing.

That said, if you want to centralize the placement of data in a field and the execution of code that uses that data, then the best bet is to create a command at the Card or Stack level that does both:

Code: Select all

on SetFieldAndUpdate theField, theValue
	set the text of fld theField to theValue
	if theValue is not equal to the lastText of fld theField then
		set the lastText of fld theField to theValue
		send UpdateField to fld theField
	end if
end SetFieldAndUpdate
And put a UpdateField command in each field you want to control in this way:

Code: Select all

on UpdateField theValue
	-- do your triggered event here
end UpdateField

-- and in case the USER changes the field...
on CloseField
	SetFieldAndUpdate short name of me, text of me
end CloseField
Then wherever you want to set the field, don't set it directly, use the command:

Code: Select all

	SetFieldAndUpdate "myField", myDataVar
I haven't compiled, run, or otherwise tested any of this code, but it seems clean to me at first glance.

The benefits are:
- Just one command to set any field
- If that field doesn't have a custom UpdateField command, nothing else happens
- Each field can have it's own custom behavior
- You can, at any time, change either a field's custom behavior or the overall command's behavior, without having to modify any code where the calls originate from

Posted: Tue May 06, 2008 11:40 pm
by ale870
It seems a good idea.
I used (and I still use) "traditional" OOP languages and I studies (and used) functional languages, but I still need to make some experience to find the best method to use "messages" (and how they are spread).

Thank you for the suggestion!