[SOLVED]-CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
[SOLVED]-CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
HI
WE have all these handlers we can "override" like closefield , exitfield, focusin, focusout , enterinfield (which is actually the RETURN key ) enter is the key on the numeric keypad.
They are not consistent as to when they are called - Ive tried to call closefield from the datagrid script, the column behaviour and it doesn't get called. ExitField gets called in the field editor (from revdata)n when I attach that behavior to a button a point the grid to it. on EscapeKey works in the same custom field editor but on closefiled doesnt.
Now I realise that somehow the datagrid takes control but when you have these lines in the default behavior :-
on closeField
## Don't delete editor within same message
send "DeleteFieldEditor" to the dgControl of me in 0 seconds
end closeField
Then you'n expect it to be called.
My question is I want to validate the data in a grid column (say date, currency etc)
But I don't want to have the call inside 3 or 4 (or more) handlers - which is the most high level handler that can be called when entering or leaving a cell and either stopping the exit/losing focus or directing the focus to another object.
i have had to put code IN ESCAPEKEY, EXITFIELD, RETURNINFIELD, arrowkeys and tabkey just to make sure I haven't missed anything.
This is too hit and miss for my liking.
What we need is a command that we can put into the messagepath that always gets called when the focus is TRIYNG to leave a cell and you either pass back a field/cell number or a object to put focus on.
In foxpro we had a very consistent system
Valid()
When()
LostFocus()
GotFocus()
Just to be more specific - I know that you Gurus out there (Trevor, Klause, Jaq, Mweider, Zryip, Simon, Bangkok, Darbx .... sorry if I left anybody out, this was just from memory) could give me a few pointers - Im assuming the DeleteFieldOpenNext is probably where I should be looking is that right?
Hope that's clear - It would also
Oh and any specific Gotchas that anyone else has found would be useful to me (and all the other beginners).
KIndest Regards Lagi
WE have all these handlers we can "override" like closefield , exitfield, focusin, focusout , enterinfield (which is actually the RETURN key ) enter is the key on the numeric keypad.
They are not consistent as to when they are called - Ive tried to call closefield from the datagrid script, the column behaviour and it doesn't get called. ExitField gets called in the field editor (from revdata)n when I attach that behavior to a button a point the grid to it. on EscapeKey works in the same custom field editor but on closefiled doesnt.
Now I realise that somehow the datagrid takes control but when you have these lines in the default behavior :-
on closeField
## Don't delete editor within same message
send "DeleteFieldEditor" to the dgControl of me in 0 seconds
end closeField
Then you'n expect it to be called.
My question is I want to validate the data in a grid column (say date, currency etc)
But I don't want to have the call inside 3 or 4 (or more) handlers - which is the most high level handler that can be called when entering or leaving a cell and either stopping the exit/losing focus or directing the focus to another object.
i have had to put code IN ESCAPEKEY, EXITFIELD, RETURNINFIELD, arrowkeys and tabkey just to make sure I haven't missed anything.
This is too hit and miss for my liking.
What we need is a command that we can put into the messagepath that always gets called when the focus is TRIYNG to leave a cell and you either pass back a field/cell number or a object to put focus on.
In foxpro we had a very consistent system
Valid()
When()
LostFocus()
GotFocus()
Just to be more specific - I know that you Gurus out there (Trevor, Klause, Jaq, Mweider, Zryip, Simon, Bangkok, Darbx .... sorry if I left anybody out, this was just from memory) could give me a few pointers - Im assuming the DeleteFieldOpenNext is probably where I should be looking is that right?
Hope that's clear - It would also
Oh and any specific Gotchas that anyone else has found would be useful to me (and all the other beginners).
KIndest Regards Lagi
Last edited by Lagi Pittas on Wed Feb 18, 2015 8:46 pm, edited 1 time in total.
Re: CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
Follow this lesson :
http://lessons.runrev.com/m/datagrid/l/ ... -to-a-cell
Then, inside the button script add :
Or if you want to apply this behavior to only column : go property inspector, switch to the Columns pane and click on the Column Behavior button.
And paste the same script inside.
Details of messages sent :
http://lessons.runrev.com/m/datagrid/l/ ... a-grid-api
http://lessons.runrev.com/m/datagrid/l/ ... -to-a-cell
Then, inside the button script add :
Code: Select all
on ExitFieldEditor pFieldEditor
answer "no change"
end ExitFieldEditor
on CloseFieldEditor pFieldEditor
put the text of pFieldEditor into tText
answer "You have typed "&tText
end CloseFieldEditor
And paste the same script inside.
Details of messages sent :
http://lessons.runrev.com/m/datagrid/l/ ... a-grid-api
-
- VIP Livecode Opensource Backer
- Posts: 212
- Joined: Fri Feb 01, 2013 1:31 am
- Location: Palo Alto, CA put williamdjamieso into tEmail / put n@gmail.com after tEmail/ revmail tEmail
- Contact:
Re: CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
Hello Lagi. I am not a super professional like the names you mentioned, nor do I understand what your goal is in figuring this out. But from what you mentioned I may have a couple things that could help you out.
First, enterInField is specifically for the button near the number pad on your keyboard that says "Enter". The returnInField i s used for the one above the shift key and any of the return keys that are available on mobile such as "search", "Go", "Enter", etc.
Second, There are two commands that get sent before losing focus from a field. One is exitField. [EDIT BY JACQUE: Exit field is sent when the user makes a change to the content and closeField is sent when the content is unchanged]. If you use breakpoints to stop the script editor, you will see that the closeField and exitField commands get sent before the new field is focused which gives you time to say for example, refocus the current field if you wanted to by writing
on ExitField
focus on me
end ExitField
That code might make it so you can never leave the field and would probably have zero application but i hope you get the point.
Third, Scripts can be places in the objects in your datagrid in the template row so that script manipulation can occur before it even gets to the datagrid so that you can test your code with no datagrid interference as they do get tricky sometimes. You can also put code in the template row group and use that instead of the row behavior, which will effectively do the same thing. But just know you have options to play with.
Fourth, See if focusIn or FocusOut help you in your situation at all. I havent really worked with those much but those are more options for you.
Fifth, from how your sentence was structured I got the impression that you might have been trying to call a Livecode message and use that to manipulate the field. I say that because of this line you wrote
So five tips, you may not need any of them. But I hope at least one of them helps you with your project.
-Will
First, enterInField is specifically for the button near the number pad on your keyboard that says "Enter". The returnInField i s used for the one above the shift key and any of the return keys that are available on mobile such as "search", "Go", "Enter", etc.
Second, There are two commands that get sent before losing focus from a field. One is exitField. [EDIT BY JACQUE: Exit field is sent when the user makes a change to the content and closeField is sent when the content is unchanged]. If you use breakpoints to stop the script editor, you will see that the closeField and exitField commands get sent before the new field is focused which gives you time to say for example, refocus the current field if you wanted to by writing
on ExitField
focus on me
end ExitField
That code might make it so you can never leave the field and would probably have zero application but i hope you get the point.
Third, Scripts can be places in the objects in your datagrid in the template row so that script manipulation can occur before it even gets to the datagrid so that you can test your code with no datagrid interference as they do get tricky sometimes. You can also put code in the template row group and use that instead of the row behavior, which will effectively do the same thing. But just know you have options to play with.
Fourth, See if focusIn or FocusOut help you in your situation at all. I havent really worked with those much but those are more options for you.
Fifth, from how your sentence was structured I got the impression that you might have been trying to call a Livecode message and use that to manipulate the field. I say that because of this line you wrote
. Just know that you cannot call Livecode made messages such as CloseField. To close a field one must use a command such as "focus on field "ThisIsTheOtherField" of me" or 'focus on nothing' These commands will automatically change send the closeField, ExitField, OpenField appropriately and reliably.Ive tried to call closefield from the datagrid script
So five tips, you may not need any of them. But I hope at least one of them helps you with your project.
-Will
Last edited by William Jamieson on Wed Feb 18, 2015 9:27 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 9662
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
Hey, Klaus, this guy is wondering why dataGrids are hard to figure out. Mmmphhh...
Oh. Hi. Ahem. You are not alone. Know that DG's work fine, and contain enormous power.
Make a simple DG, give it a little content, and open the message watcher. Suppress everything but messages that are handled. Now put this in the group script:
Change the contents of a field, and click in another field. Note that the "closeField" handler does not fire, even though you see it in the message watcher. Note that the "dgMouseUp" message is indeed detected in the message box. The DG has a lot going on inside, and it traps "closeField". But it allowed dgMouseUp to pass to your group script. That is because this message was not used internally.
Now put this into the group script:
Again, can you use this instead of "closeField"? Is it robust enough to be a valid substitute? Should you have to worry about this sort of thing? Good luck.
Craig Newman
Oh. Hi. Ahem. You are not alone. Know that DG's work fine, and contain enormous power.
Make a simple DG, give it a little content, and open the message watcher. Suppress everything but messages that are handled. Now put this in the group script:
Code: Select all
on closefield
put "CloseField" && random(99)
end closefield
on dgMouseUp
put "DGMouseUp" && random(999)
end dgMouseUp
Now put this into the group script:
Code: Select all
on selectionChanged
put " SC" && random(999)
end selectionChanged
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
Re: CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
Hi
Thank you for all your help.
I created a small test stack and "played" for about 4 hours - I have nothing better to do of course.
Here are a few of the handlers I played with
I have a scrolling field and bunched up the messages and showed them.
Anyway unless there is something else that are have missed here is the problem.
ALL of these fire on keystroke (rawkeydown is needed for the non printable) but however I access the data in the cell it ALWAYS the data as it was when the cell/column got focus.
When you leave the cell and go to another cell by pressing tab or enter rawkeyup gives you the data as it is - but its now to late we have moved to the new cell.
"on SelectionChanged" just tells you you have moved to a new row/column but it is only in a non editing mode.
What I want to be able to do is take control of the editing so I can control all input BEFORE final validation and go to any object/target I want.
I wrote a routine below
Which works 90% the way I want it to work. The problem is when I go into the field the text isn't selected - I need it to select all the text and if they hit any printable key the field is blanked and so they can start typing.
Ok Update -- while writing this I had a flash of inspiration and tried putting into the TEXTChanged event and the RAWKEYUP event the code "GET THE TEXT of the TARGET" and "GET THE SELECTEDCHUNK of the TARGET" . So now I have the insertion point and the actual data -- we're making progress.
So I added the focus on me / focus on the target (tried both) in the exit field event . This stopped it from going to the next cell but stayed on the current cell but it was not open for editing.
i even added a "send mouse double up to me" and all permutations thereof (well my head is spinning so it was most )
so I added the code below - It has the correct line and key (column name) but still won't do it.
Basically what I need now is a way to stay on the current field in edit mode with the insertion point at the end
Without "focus on the target" it goes to the next field whatever I do.
I'm stumped - but bloody close
Thanks everybody for your help (btw it's now been 6 hours)
Thank you for all your help.
I created a small test stack and "played" for about 4 hours - I have nothing better to do of course.
Here are a few of the handlers I played with
Code: Select all
on RawKeyDown
local lnRow, lcContents, laRowData
global lcTheData
put the dgHilitedLines of group me into lnRow
put the dgDataOfLine[lnRow] of group me into laRowData
Put "RawkeyDown " & laRowData["number"] into line (the number of lines in lcTheData + 1) of lcTheData
pass RawKeyDown
end RawKeyDown
on TextChanged
local lnRow, lcContents, laRowData
global lcTheData
put the dgHilitedLines of group me into lnRow
put the dgDataOfLine[lnRow] of group me into laRowData
Put "TextChanged " & laRowData["number"] into line (the number of lines in lcTheData + 1) of lcTheData
pass TextChanged
end TextChanged
on RawKeyUp
local lnRow, lcContents, laRowData
global lcTheData
put the dgHilitedLines of group me into lnRow
put the dgDataOfLine[lnRow] of group me into laRowData
Put "RawkeyUp " & laRowData["number"] into line (the number of lines in lcTheData + 1) of lcTheData
end RawKeyUp
on mouseUp pMouseBtnNum
local lcColData, lcColumn
global lcTheData
put the dgColumn of the target into lcColumn
if lcColumn is not empty then
put GetDataOfIndex(the dgIndex of the target, lcColumn) into lcColData
Put "Mouseup >>> " & lcColData into line (the number of lines in lcTheData + 1) of lcTheData
end if
end mouseUp
Anyway unless there is something else that are have missed here is the problem.
ALL of these fire on keystroke (rawkeydown is needed for the non printable) but however I access the data in the cell it ALWAYS the data as it was when the cell/column got focus.
When you leave the cell and go to another cell by pressing tab or enter rawkeyup gives you the data as it is - but its now to late we have moved to the new cell.
"on SelectionChanged" just tells you you have moved to a new row/column but it is only in a non editing mode.
What I want to be able to do is take control of the editing so I can control all input BEFORE final validation and go to any object/target I want.
I wrote a routine below
Code: Select all
function CurrencyValidation pAmount, pTheKey
constant kREG = "^[0-9]{1,5}+(\.[0-9]{1,2})$"
local lcText
put pAmount into lctext
if pTheKey is "." then
put lcText & ".00" into lcText -- The Regex checks the whole string so 123 would not validate
else
put lcText & pTheKey into lcText
end if
if "." is not in lcText then put lcText & ".00" into lcText -- Still typing left side of Decimal
if matchText(lcText,kREG) then
return TRUE
end if
beep
return FALSE
end CurrencyValidation
Ok Update -- while writing this I had a flash of inspiration and tried putting into the TEXTChanged event and the RAWKEYUP event the code "GET THE TEXT of the TARGET" and "GET THE SELECTEDCHUNK of the TARGET" . So now I have the insertion point and the actual data -- we're making progress.
So I added the focus on me / focus on the target (tried both) in the exit field event . This stopped it from going to the next cell but stayed on the current cell but it was not open for editing.
i even added a "send mouse double up to me" and all permutations thereof (well my head is spinning so it was most )
so I added the code below - It has the correct line and key (column name) but still won't do it.
Code: Select all
on ExitFieldEditor pFieldEditor
put the dgHilitedLines of group "datagrid 1" into theLine
put the dgcolumn of the target into theColumn
send "EditKeyOfIndex theColumn, theline" to the group "datagrid 1" in 30
focus on the target
end ExitFieldEditor
Without "focus on the target" it goes to the next field whatever I do.
I'm stumped - but bloody close
Thanks everybody for your help (btw it's now been 6 hours)
-
- VIP Livecode Opensource Backer
- Posts: 9662
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
Not sure this addresses your problem.
When you click on a "field" in a data grid, the "dgMouseUp" message is sent and may be trapped in the group script, as we saw, and the field is named, say, "Col 1 0002", which is column 1, row 2 It is simple to:
Now go to the DG guide and on page 224 see if you can figure out how to use the commands like "editCell" or editFieldText". When do figure that out, please write back and tell *me*.
Craig
When you click on a "field" in a data grid, the "dgMouseUp" message is sent and may be trapped in the group script, as we saw, and the field is named, say, "Col 1 0002", which is column 1, row 2 It is simple to:
Code: Select all
select fld "col 1 0002"
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7236
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
William Jamieson wrote:Second, There are two commands that get sent before losing focus from a field. One is exitField. This is when the user clicks of the field and is not focusing on another field. The other is closeField. This is when the user is trying to focus in another field.
Not exactly. ExitField is sent when the field loses focus but its content has not changed. CloseField is sent when the field loses focus and its content has changed. The destination or the next target is immaterial.
Just a little clarification: You can't make a field close by issuing the message that is sent after it closes, which applies to any message that occurs as a result of a user action. But you can insert any LC system message into a handler and it will traverse the message hierarchy normally.Just know that you cannot call Livecode made messages such as CloseField. To close a field one must use a command such as "focus on field "ThisIsTheOtherField" of me" or 'focus on nothing' These commands will automatically change send the closeField, ExitField, OpenField appropriately and reliably.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
Re: CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
HI
I was not calling closefiled I meant I was trying to trap it.
Actually its with the closefieldeditor I was trapping for the grid.
I put this code
Into the closefieldeditor event as well, with and without the setfocus to me / target but I was playing with the "exitfield" event because i could just type tab without typing anything else (lazy? .. maybe )
I thought the EditKeyoFindex calls the standard editext routine that will open for editing - otherwise it seems i'm going to have to use 8000 lines of datagrid code for each column - or so it seems.
Maybe I need to go into the revdatagrid library and add an extra routine there if I ever get out alive -
The revdatagrid library is all there "opensource" couldn't we start a thread where some of the showstoppers can be brought up[ and added to our "own version"
The datagrid is VERY powerful in reality the fact that you (Trevor) could code it in Livecode shows the power of livecode (and the tenacity of Trevor Devore) but for 200 ish lines more we could save a lot of questions on the forum - How about it Gurus?
Regards Lagi
I was not calling closefiled I meant I was trying to trap it.
Actually its with the closefieldeditor I was trapping for the grid.
I put this code
Code: Select all
put the dgHilitedLines of group "datagrid 1" into theLine
put the dgcolumn of the target into theColumn
send "EditKeyOfIndex theColumn, theline" to the group "datagrid 1" in 30
I thought the EditKeyoFindex calls the standard editext routine that will open for editing - otherwise it seems i'm going to have to use 8000 lines of datagrid code for each column - or so it seems.
Maybe I need to go into the revdatagrid library and add an extra routine there if I ever get out alive -
Just a suggestion"Oh the pain, the pain!" -- Dr Zakary Smith.
The revdatagrid library is all there "opensource" couldn't we start a thread where some of the showstoppers can be brought up[ and added to our "own version"
The datagrid is VERY powerful in reality the fact that you (Trevor) could code it in Livecode shows the power of livecode (and the tenacity of Trevor Devore) but for 200 ish lines more we could save a lot of questions on the forum - How about it Gurus?
Regards Lagi
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
[SOLVED] CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
Hi
After another couple of hours where my meticulous naming conventions lost the plot ...
And I mixed up EditCellofIndex for editcell (quite why index is different to the row when I only loaded 4 rows in the content field I'll never know, unless its to do with headers sorting the columns).
Anyway here is the code that will be my starting position for moving to any cell depending on what is in the field
Notice the owrds bot, string, date etc are my way of testing that I can move around depending on what is in the cell.
I can now make the grid focus wherever I want or move anywhere in the grid - which is a bonus
Still will need to work out if I need to pass exitfieldeditor and closefieldeditor - probably not.
Now this is in the "number" column behavior, so my idea now is to put this in the grid script with my other code and have a switch statement for specific columns.
Ie if the column contains dates it calls a validate date routine, if numbers validate currency etc.
The actual key by key validation will be done in the textchanged event because now I have the insertion point and the actual content I can overide the "editing keys" like delete, backspace etc.
and so I can go to bed with "The Eternal Sunshine of the Spotless Mind "
Thanks everyone
After another couple of hours where my meticulous naming conventions lost the plot ...
And I mixed up EditCellofIndex for editcell (quite why index is different to the row when I only loaded 4 rows in the content field I'll never know, unless its to do with headers sorting the columns).
Anyway here is the code that will be my starting position for moving to any cell depending on what is in the field
Code: Select all
on ExitFieldEditor pFieldEditor
put the dgHilitedLines of group "datagrid 1" into theLine
put the dgcolumn of the target into theColumn
put "Exit: " & ttext
if txext contains "top" then
send "EditCell string, 3" to the group "datagrid 1" in 60
end if
if txext contains "bot" then
send "EditCell string, 4" to the group "datagrid 1" in 60
end if
end ExitFieldEditor
on CloseFieldEditor pFieldEditor
put the text of pFieldEditor into tText
put the dgHilitedLines of group "datagrid 1" into theLine
put the dgcolumn of the target into theColumn
put "Close: " & ttext
if ttext contains "date" then
send "EditCell " & "date, " & theline to the group "datagrid 1" in 60
end if
if ttext contains "top" then
send "EditCell string, 1" to the group "datagrid 1" in 60
end if
if ttext contains "bot" then
send "EditCell string, 4" to the group "datagrid 1" in 60
end if
if ttext contains "string" then
send "EditCell string, " & theline to the group "datagrid 1"
end if
pass CloseFieldEditor
end CloseFieldEditor
Notice the owrds bot, string, date etc are my way of testing that I can move around depending on what is in the cell.
I can now make the grid focus wherever I want or move anywhere in the grid - which is a bonus
Still will need to work out if I need to pass exitfieldeditor and closefieldeditor - probably not.
Now this is in the "number" column behavior, so my idea now is to put this in the grid script with my other code and have a switch statement for specific columns.
Ie if the column contains dates it calls a validate date routine, if numbers validate currency etc.
The actual key by key validation will be done in the textchanged event because now I have the insertion point and the actual content I can overide the "editing keys" like delete, backspace etc.
-- LagiIf at first you don't succeed ... Cheat!!
and so I can go to bed with "The Eternal Sunshine of the Spotless Mind "
Thanks everyone
Last edited by Lagi Pittas on Thu Feb 19, 2015 12:21 am, edited 2 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 212
- Joined: Fri Feb 01, 2013 1:31 am
- Location: Palo Alto, CA put williamdjamieso into tEmail / put n@gmail.com after tEmail/ revmail tEmail
- Contact:
Re: [SOLVED]-CLOSEFIELD EXITFIELD FOCUSIN GRID VALIDATION
Yep Jacque! You are absolutely right about that. Sorry about the confusion of the ExitField and CloseField. Look at Jacques response for more clarity.
Glad you were able to get this solved Lagi!
-Will
Glad you were able to get this solved Lagi!
-Will