Page 1 of 1

Message To Field When Content Changes

Posted: Wed Mar 04, 2015 10:52 am
by WaltBrown
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

Re: Message To Field When Content Changes

Posted: Wed Mar 04, 2015 12:51 pm
by AndyP
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

Re: Message To Field When Content Changes

Posted: Wed Mar 04, 2015 2:08 pm
by magice
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.

Re: Message To Field When Content Changes

Posted: Wed Mar 04, 2015 5:23 pm
by WaltBrown
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

Re: Message To Field When Content Changes

Posted: Wed Mar 04, 2015 5:31 pm
by FourthWorld
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

Re: Message To Field When Content Changes

Posted: Wed Mar 04, 2015 5:49 pm
by dunbarx
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

Re: Message To Field When Content Changes

Posted: Wed Mar 04, 2015 5:55 pm
by FourthWorld
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.

Re: Message To Field When Content Changes

Posted: Wed Mar 04, 2015 6:06 pm
by WaltBrown
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.

Re: Message To Field When Content Changes

Posted: Wed Mar 04, 2015 9:43 pm
by dunbarx
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