How to detect changed text in a field?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

How to detect changed text in a field?

Post by ale870 » Tue May 06, 2008 9:27 am

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!

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Tue May 06, 2008 10:00 am

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

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Tue May 06, 2008 10:49 am

Most likely you do not really want the closeField messsage, but you want to vote for bug 5888
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Location: Kent, UK
Contact:

Post by gyroscope » Tue May 06, 2008 11:13 am

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?

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Tue May 06, 2008 11:51 am

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.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Location: Kent, UK
Contact:

Post by gyroscope » Tue May 06, 2008 11:58 am

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.

:)

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Tue May 06, 2008 12:06 pm

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

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Post by ale870 » Tue May 06, 2008 12:32 pm

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

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Tue May 06, 2008 1:01 pm

Please calm down!

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

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Post by ale870 » Tue May 06, 2008 5:12 pm

Ok, Ok :D
I will check "selectionchanged" then I will be angry later... :D

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Tue May 06, 2008 5:18 pm

ale870 wrote:Ok, Ok :D
I will check "selectionchanged" then I will be angry later... :D
OK, deal! :-D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Post by FourthWorld » Tue May 06, 2008 7:47 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Post by ale870 » Tue May 06, 2008 9:18 pm

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!

Nonsanity
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 86
Joined: Thu May 17, 2007 9:15 pm
Location: Maryland, USA
Contact:

Post by Nonsanity » Tue May 06, 2008 10:14 pm

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
~ Nonsanity
~ Chris Innanen

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Post by ale870 » Tue May 06, 2008 11:40 pm

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!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”