field changed message

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

field changed message

Post by adventuresofgreg » Wed Oct 17, 2012 11:11 pm

Hi: there is probably a simple way of doing this, but I can't seem to figure it out. I want a handler in the script of a field that does something when the content of the field has changed. I don't really want to set up a loop to check for a change - unless i have to I guess. The user does NOT change this field. It's contents are streamed from a port.

Thanks!
Greg

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: field changed message

Post by sturgis » Wed Oct 17, 2012 11:42 pm

There are a couple options. There is the textchanged message that will trigger even with programmatic text changes to the field. Though I'm not sure its necessary because if you're reading from a port and putting new content into the field, you could manually call a handler right after you add the text to the field.

Either method should work.

Code: Select all

on textchanged
## do something
end textchanged

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: field changed message

Post by adventuresofgreg » Thu Oct 18, 2012 12:28 am

Thanks. When I search for "textChanged" it is not found in the dictionary

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: field changed message

Post by sturgis » Thu Oct 18, 2012 12:51 am

textChanged is a recent addition. What version of livecode are you running? There are some more recent versions where it is available but not yet in the dictionary, though I think the most recent does show textChanged.

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: field changed message

Post by adventuresofgreg » Thu Oct 18, 2012 1:40 pm

5.5.1

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: field changed message

Post by sturgis » Thu Oct 18, 2012 1:55 pm

Yep, it should be there. (though you can get 5.5.2 now)

To test, create a field and put the following in its script.

Code: Select all

on textChanged
  put the text of me
end textChanged
As you type in the field it should echo the contents to the message box. (the first char you type might shift focus to the msg box so you'll have to click back into the field)

Heres most of the 5.5.2 dictionary entry..
Summary:
Sent when the content of a field has changed.

Examples:
on textChanged -- enable the save button when a change is made
enable button "save"
end textChanged


Is dispatched by the field whenever a user (or simulated user) action causes the content of the field to change.

Comments:
Handle the textChanged message if you want to perform an action when the content of a field changes.

The message is sent immediately after the input operation completes, but before a screen update is requested. The corresponding update occurs at the end of the first command in the textChanged handler. This means that you can lock the screen at the first line of the handler to delay the screen update (allowing you to modify the content of the field without any flicker).

To prevent potential for infinite recursion, calls to textChanged do not nest. Once a textChanged handler is being executed for a given field, another textChanged message is not sent to it, should a subsequent one be triggered.

The textChanged message is sent after messages such as keyDown and pasteKey but before messages such as keyUp.

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: field changed message

Post by adventuresofgreg » Sun Oct 21, 2012 2:29 pm

Hi: The TextChanged handler doesn't work in my case because I am changing the fields contents with a script, and not by TYPING into the field. This handler only works when the field has been entered, and then contents changed.

timlit
Posts: 9
Joined: Tue Feb 22, 2011 12:15 am

Re: field changed message

Post by timlit » Sun Oct 21, 2012 3:54 pm

I might do as follows:

Code: Select all

- put field id (i) into tHistory[i]
- put the_external_value into field[i]
- if tHistory[i] <> field id (i) then answer "the value has changed!"
in data packed systems, I generally find it helpful to pass gui-targeted values through arrays.

hth,
Tim

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: field changed message

Post by sturgis » Sun Oct 21, 2012 4:10 pm

Interesting. I could have sworn one of the recent versions of lc had a textchanged that would respond to script changes.

And this line

Code: Select all

Is dispatched by the field whenever a user [b](or simulated user) action[/b] causes the content of the field to change.
seems to indicate that it still should.

However if you look at the earlier answers there is this..
Though I'm not sure its necessary because if you're reading from a port and putting new content into the field, you could manually call a handler right after you add the text to the field.
Meaning..

Code: Select all

on handlerthatchangesthefield
do stuff here
do more stuff
-- run the command for when the field contents change
myFieldChanged -- 
end handlerthatchangesthefield

command myFieldChanged
do whateve you need done when the field changes
end myFieldChanged

Not sure I see a problem here even though the textchanged doesn't work as expected.

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: field changed message

Post by adventuresofgreg » Sun Oct 21, 2012 4:38 pm

Thanks - there isn't really a big problem with adding my text changed stuff to the handler that reads from the port and writes to the field. That works fine, and might be the fastest way of doing it. However, there *may* be times when the port isn't working (data server streaming to the port is down), and I may want to provide some other method of writing data to that field aside from reading from the port. In this case, my handler to act upon a change in the contents of the field (if delt with in the port writing handler) won't work, and would need to be duplicated - which is what I'm trying to avoid. But... I could just write a handler to handle it - or a function. And just call the function in the port handler - and the same functioon from any new thing I have to write.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: field changed message

Post by jacque » Sun Oct 21, 2012 7:31 pm

sturgis wrote:Interesting. I could have sworn one of the recent versions of lc had a textchanged that would respond to script changes.
I read it the same way but yeah, "putting" text into a field doesn't do it. Apparently "user simulated" changes means simulated typing. I see that the "type" command does trigger a textchanged message.

Interesting.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: field changed message

Post by mrcoollion » Tue Oct 27, 2015 9:28 am

Still does not work in version 7.06 if I enter a value in a field from a script. :(

I will solve it with a handler ...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: field changed message

Post by bn » Tue Oct 27, 2015 11:53 am

Still does not work in version 7.06 if I enter a value in a field from a script. :(
I will solve it with a handler ...
why don't you send "textChanged" after you field changing script is done?

Code: Select all

on mouseUp
   put "asldfkj" after field "input"
   send "textChanged" to field "input"
end mouseUp
Kind regards
Bernd

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: field changed message

Post by mrcoollion » Tue Oct 27, 2015 6:14 pm

Thx Bernd :)

Post Reply