Intercepting messages in a editable table field

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Intercepting messages in a editable table field

Post by MaxV » Tue Aug 27, 2013 2:01 pm

Hi,
I have a simple task, using an editable table field: when user add data, something happen.
The problem seem that an editable table field doesn't pass enterInField, returnInField, TabKey messages! They are used internally and passed no more! :shock:
How can I intercept those message in an editable table field?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: Intercepting messages in a editable table field

Post by Martin Koob » Tue Aug 27, 2013 2:34 pm

Hi

If you handle enterInField in the field script then the enterInField message won't pass further along the message path unless you tell it to do so with a pass statement

ie

on enterInField
answer "field"
pass enterInField
end enterInField

This will pass the message to the next object in the path be it a group or the card where it can be handled again.

If you don't handle enterInField in the field script it will pass along the message path until it is handled by a group, the card, the stack etc.

Martin

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Intercepting messages in a editable table field

Post by MaxV » Tue Aug 27, 2013 3:14 pm

It's not so easy. In a simple field on enterInField scripts works, but if you transform the field in a basic table (property->Table->Basic table object ON and Cell editing ON) you can't intercept keys as usual, for example this don't work:

Code: Select all

on returninfield   
   Answer "hello"
   pass    returninfield   
end  returninfield

on enterinfield   
   Answer "hello"
   pass  enterinfield   
end  enterinfield

on tabKey
    Answer "hello"
   pass  tabKey
end tabKey
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10367
Joined: Wed May 06, 2009 2:28 pm

Re: Intercepting messages in a editable table field

Post by dunbarx » Tue Aug 27, 2013 3:58 pm

In a table field, the engine creates a "phantom" field that overlies the cell of interest. It is this phantom field that does all the work.

Make a table field on a blank card. Put this into the card script:

Code: Select all

on enterinfield
   put the value of target & return & the name of  the target
end enterinfield
Type into a cell, and hit "enter".

You have to use this field when trying to manipulate the table field functionality.

Craig Newman

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: Intercepting messages in a editable table field

Post by Martin Koob » Tue Aug 27, 2013 9:54 pm

Sorry MaxV.

I missed the fact you were talking about a table field.

Martin

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Intercepting messages in a editable table field

Post by MaxV » Wed Aug 28, 2013 11:41 am

WOW it isn't just a single field, but every cell has a its phantom field like field "revCell-2,1".
At the moment I bypassed the problem with an external button ("FINISHED TO USE TABLE" :lol: ) .
However what is the best object to use for an editable table? For example: I wish to save all table data every time a cell is edited.
Datagrid is not editable like table field, user can't add data, so any suggestion?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 256
Joined: Sun May 27, 2007 8:19 pm

Re: Intercepting messages in a editable table field

Post by Martin Koob » Wed Aug 28, 2013 3:50 pm

Hi I have to admit that I don't really know how table fields work. Out of curiosity I thought I would look at the message watcher to see what happens when you edit a table field. There are a lot of messages cREVtable flying around. Some with the data that is entered as parameters, many with no parameters. If a phantom field is closed you can catch when that happens with getProp cREVtable and look at the target. The target name contains the cell that was closed but doesn't tell you if it was edited or not but tells you the user left the field so there is a chance they did something while it was open. If you press return in the field you can also catch the returnInField the same way but a cREVtable will also be sent from the phantom field.

Here are some test handlers to put in the stack script to catch those events.

Code: Select all

getprop cREVtable
   if the short name of the target contains "REVcell" then
      answer "Close" && char 9 to - 1 of the short name of the target
      end if
   pass cREVtable
end cREVtable

on returninfield
   if the short name of the target contains "REVcell" then
      answer "return" && char 9 to - 1 of the short name of the target
   end if
   pass returninfield
end returninfield
Another interesting thing is that if you put those two handlers in the card script the cREVtable message is handled by the card but the returnInField message is not.
Further more if you put those two handlers in a group script that contains the table field the neither the cREVtable message nor returnInField message is handled by the group.

Again I don't know know enough about this to know if this would work for your purposes but I thought it was interesting so I thought I would pass this along.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10367
Joined: Wed May 06, 2009 2:28 pm

Re: Intercepting messages in a editable table field

Post by dunbarx » Wed Aug 28, 2013 4:06 pm

Martin.

Pretty sure that there is only one phantom field, the engine creating, sizing and naming it according to the loc of the mouseclick. LC knows, after all,where its tabs and lines are, and you or I for that matter, could do the same. The field is ephemeral, created and destroyed as needed.

It allows there to be only a single table field, formatted as we see, and a single "working" field, like a virtual particle in empty space, to manage the very convenient functionality of that field type.

Craig

Post Reply