Message To Field When Content Changes

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm
Location: NE USA

Message To Field When Content Changes

Post by WaltBrown » Wed Mar 04, 2015 10:52 am

Hi! Probably an easy one - searched for an answer but didn't find it.

I have fields (effectively standardized, or template fields I use in multiple stacks) whose content can be changed, either manually or programmatically. I have "standard" template scripts for validating certain input types, and possibly performing other actions.

I have worked with "closeField", "textChanged", "exitField", "focusOut", etc in the field scripts individually or in the stack script if the field scripts capture the messages. They work fine for user changes to the field contents. I would also like to trigger a validation script in a given field if it's contents are changed programmatically.

For example I may have multiple stacks into which I have placed a "standard" field template, from my personal library stack, I have created called "fUserAccountNumber". Depending on the current goal of the specific stack I place it in it might allow user input in certain conditions, or it may be updated only by an action in some other script, possibly in another stack.

The question is: is there a message triggered by a programmatic change in field contents? if not, should the "textChanged" message be triggered by a programmatic change in field contents?

Thanks,
Walt
Walt Brown
Omnis traductor traditor

AndyP
Posts: 449
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Message To Field When Content Changes

Post by AndyP » Wed Mar 04, 2015 12:51 pm

Hi Walt,

You can simulate typing in a field by using the "type" command.
This will result in a textChanged message being sent which you can then action upon.

on mouseUp
set the typingRate to 0 // no delay
type fld "myField"
put "myData" into fld "myField"
end mouseUp
Andy Piddock

http://2108.co.uk/tinyide/ - Mini LC IDE alternative

http://2108.co.uk/script-editor-themer/ - Script Editor colour theming

http://livecodeshare.runrev.com/stack/897/LiveCode-Multi-Search - Search across 8 LC resources

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Message To Field When Content Changes

Post by magice » Wed Mar 04, 2015 2:08 pm

One of the great things about LC is that messages that are sent by the engine can also be sent with script. So, for example, if you have a mouseUp handler in a button, you can use "send mouseUp to btn "myButton" to send that message from a handler. The same can be done for "exitField", "focusOut", etc.

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm
Location: NE USA

Re: Message To Field When Content Changes

Post by WaltBrown » Wed Mar 04, 2015 5:23 pm

Thanks, both good answers. The issue is the field won't know ahead of time what script might update it, and the script may not know the specific field name (ie passed by reference). I'm thinking of re-architecting to a PubSub kind of architecture, so the fields and the scripts updating them don't have to know about each other ahead of time.

Walt
Walt Brown
Omnis traductor traditor

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

Re: Message To Field When Content Changes

Post by FourthWorld » Wed Mar 04, 2015 5:31 pm

You might also consider using getProp and setProp as triggers for sending any special messages while getting and setting field values, e.g.:

Code: Select all

setProp MyText, pText
   set the text of me to MyText
   dispatch "textChanged"
end MyText
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6186
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Message To Field When Content Changes

Post by dunbarx » Wed Mar 04, 2015 5:49 pm

Richard.

Clever. That would be fine if the user "sets" the text of the field.

But I think the issue is when one "puts" text into a field. As was mentioned, any given handler can explicitly send a message to that field, before, during or after it does what it does, especially when it is putting text into that field. But that "explicit" thing makes the concept just a little cumbersome.

Didn't we once talk about the "messageMessage"? isn't that like a universal "frontMessage", that might be used here? I have not thought of that in years.

The desire is to be able to have such a thing lurking in front, so that it can trigger an event based on whatever parameters or object references can be ascribed to it. Not a frontScript, but rather a frontMessage. This seems like a powerful tool.

@Walt. However this turns out, the idea of always setting text instead of putting text would allow you to use Richard's suggestion. You have to do that everywhere, however.

Craig

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

Re: Message To Field When Content Changes

Post by FourthWorld » Wed Mar 04, 2015 5:55 pm

True, it would mean any script that changes the field's contents would need to be updated to use the new custom property setting.

As for the messageMessages, it's useful for diagnostics but not much more. It traps a subset of info for every message, so it's both not complete enough for many non-diagnostic tasks and so complete in terms of the messages it handles (all of them) that it adds a fair bit of load to the system.

Might be nice to have a more specific generalized message trap, but then again it may be more efficient to just trap changes to built-in object properties so the handling is specific to the object being monitored.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

WaltBrown
Posts: 466
Joined: Mon May 11, 2009 9:12 pm
Location: NE USA

Re: Message To Field When Content Changes

Post by WaltBrown » Wed Mar 04, 2015 6:06 pm

I'm going to revisit the Subscriber/Publisher IPC mechanism for a bit (for this and the pseudo-multitasking discussions). I've sketched out a spec for a utility stack and hope to put together a V1 tonight.
Walt Brown
Omnis traductor traditor

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6186
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Message To Field When Content Changes

Post by dunbarx » Wed Mar 04, 2015 9:43 pm

Richard.

It could be along the lines of "setProp" and "getProp".

"controlChanged tControl"

Similar to the wonderful "mouseMove", it triggers when anything changes in a control, card or stack. A loc move, a foreColor change, text inserted under script control, whatever. Essentially a "textChanged" message for handler generated changes in fields, as an instance.

Of course, you are correct to be concerned about all those messages clogging up the system, though perhaps they can be turned off with a property? Is this worth placing in the "Feature Requests" area?

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”