Hi guys,
probably another silly question of mine:
I would like to give the user (which is me ) the possibility of firing the program action either by mouseclick or by hitting the enter or the return key, after me has entered a value in a field.
I am wondering if I have to copy the complete code not only in the button script but also twice in the field script (with returnKeyUp and enterKeyUp (?)) to achieve this? I know of rawKeyUp but that won't work for me, because then some user input checks are triggered too soon.
[Solved] Action on return, enter and also on button click
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
[Solved] Action on return, enter and also on button click
Last edited by redfield on Sun Jun 16, 2019 12:47 pm, edited 1 time in total.
Re: Action on return, enter and also on button click
Notwithstanding that there may be other considerations or approaches (eg on closeField), depending on your user interface and program flow, where you have multiple possible triggers of the same code, you can easily avoid code duplication by leveraging the message path.
Create a handler in a suitable place in the message path (group script, card script or stack script, for example)Then in the different trigger places, you canetc etc for returnInField, closeField
Create a handler in a suitable place in the message path (group script, card script or stack script, for example)
Code: Select all
on validateInput pData
if pData is not an integer then
answer "Invalid input. You entered" && quote & pData & quote && "which is not an integer."
end if
--and or your code that you want to avoid duplicating
end validateInput
Code: Select all
on enterInField
put the text of me into tData
validateInput tData
end enterInField
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Action on return, enter and also on button click
I think Sparkout and I will be on the same page.
Make a few buttons and fields. Name one button "B1". Name one field "F1".
In the card script:
And as Sparkout said, add as many other message traps as you need. Be aware that you may need to pass some of those messages, depending on what you are doing.
A behavior script would do much the same thing.
Craig
Make a few buttons and fields. Name one button "B1". Name one field "F1".
In the card script:
Code: Select all
on mouseup
if the short name of the target = "b1" then doAction
end mouseup
on closeField
if the short name of the target = "f1" then doAction
end closeField
on doAction
answer "Get going..."
end doAction
A behavior script would do much the same thing.
Craig
Re: Action on return, enter and also on button click
Thanks a lot, this is working very well. I put the whole script in a custom handler and then call that handler from different fields and buttons.
(Is there a way here to mark topics as solved??)
(Is there a way here to mark topics as solved??)
Re: Action on return, enter and also on button click
Yes, you go to your first post in the thread, click on the 'edit' pencil, and in the highlighted box above the post type "Solved" in whatever form you like!
* [Solved]
* {Solved}
* : Solved :
* --Solved...
Invent a new one if you like
There are many variations, such as : * [Solved]
* {Solved}
* : Solved :
* --Solved...
Invent a new one if you like