Modifying field contents with script
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Modifying field contents with script
If you use mouseUp nothing works . . .
- Attachments
-
- Field Me Up.livecode.zip
- Stack.
- (6.32 KiB) Downloaded 85 times
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Modifying field contents with script
Hi all
Apologies if I was not clear at the start. Please see my original post.
Simple case – card has only 1 field
1. User clicks on field
2. Text "hello" is added to the end of the field
My simple original script works:
(Simpler to delete "char -1" but I was keeping it general)
Complex case - card has several fields
1. User clicks on any of the several fields
2. Text "hello" is added to the end of that particular field
My attempt was originally:
which did not work. My modified script does work:
Apologies if I was not clear at the start. Please see my original post.
Simple case – card has only 1 field
1. User clicks on field
2. Text "hello" is added to the end of the field
My simple original script works:
Code: Select all
put "hello" after char -1 of fld 1
Complex case - card has several fields
1. User clicks on any of the several fields
2. Text "hello" is added to the end of that particular field
My attempt was originally:
Code: Select all
put the name of fld 1 into tName
put hello after char -1 of tName
Code: Select all
put the ID of the target into tID
put hello after fld ID tID
Kaveh
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Modifying field contents with script
Kaveh.
OK, that is what I thought you wanted. Your handlers will work fine. The "complex" case is likely best, since it will cover you if you ever add or delete other fields. The handler is structured robustly, and will work in all cases.
What message are you trapping to make this work? "MouseUp"? If so, it seems that you are using locked fields. Otherwise that message is not sent. Always try to include that information, as it helps us understand what you are dealing with.
Also, ALWAYS quote literals:
And lastly, and it hardly matters, but know that you could have simply:
As was mentioned earlier.
Craig
OK, that is what I thought you wanted. Your handlers will work fine. The "complex" case is likely best, since it will cover you if you ever add or delete other fields. The handler is structured robustly, and will work in all cases.
What message are you trapping to make this work? "MouseUp"? If so, it seems that you are using locked fields. Otherwise that message is not sent. Always try to include that information, as it helps us understand what you are dealing with.
Also, ALWAYS quote literals:
Code: Select all
put "hello" after fld ID tID
Code: Select all
put "hello" after the target
Craig
Re: Modifying field contents with script
@kaveh - i think what people here are trying to help you with is limited by the information provided. The user interface doesn't really make sense as described. Is the user going to be fed data in a locked field and will have to click a button to change it? Or do you want to modify the text entered by the user?
Your comments hint at wanting to abstract a command to modify fieldsat card or script level and need some way of identifying the field being targeted (otherwise you could just put the script in the field)
The key thing to know is
a) will the user enter or modify text? or,
b) will the field be populated by other means, eg a popup menu, database etc?
If the latter, that means you can use locked fields, which will provide 'the target'. However this would still require the user to click on a locked field, which user-interface wise can be tricky. Or you could just use the textChanged handler to get the identifier for your field.
If the fields aren't locked (ie. the user can enter or modify the data) then you can either
a) use the enterField handler to store a script local or global variable with a field identifier (usually the long id is best) that will provide you an id you can use in an abstracted script, eg in the card or stack, to target that field, or
b) trigger an action during text input (with the textChanged handler) or after input/exiting the field (with the closeField handler)
I think the reason for these back-and-forth comments is that no one really understands what you have in mind - as Craig says a flow-charted process would be very helpful. Alternatively, why don't you post a mockup of what it is your planning?
Your comments hint at wanting to abstract a command to modify fieldsat card or script level and need some way of identifying the field being targeted (otherwise you could just put the script in the field)
The key thing to know is
a) will the user enter or modify text? or,
b) will the field be populated by other means, eg a popup menu, database etc?
If the latter, that means you can use locked fields, which will provide 'the target'. However this would still require the user to click on a locked field, which user-interface wise can be tricky. Or you could just use the textChanged handler to get the identifier for your field.
If the fields aren't locked (ie. the user can enter or modify the data) then you can either
a) use the enterField handler to store a script local or global variable with a field identifier (usually the long id is best) that will provide you an id you can use in an abstracted script, eg in the card or stack, to target that field, or
b) trigger an action during text input (with the textChanged handler) or after input/exiting the field (with the closeField handler)
I think the reason for these back-and-forth comments is that no one really understands what you have in mind - as Craig says a flow-charted process would be very helpful. Alternatively, why don't you post a mockup of what it is your planning?
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Modifying field contents with script
Hi Craig
Great to have this interaction with you after a long time!
I take your points about the literal "hello". it was sloppy!
Did you see the minimal stack I uploaded? That answers your questions. I have 3 locked fields, yes. And the stack script is:
Great to have this interaction with you after a long time!
I take your points about the literal "hello". it was sloppy!
Did you see the minimal stack I uploaded? That answers your questions. I have 3 locked fields, yes. And the stack script is:
Code: Select all
local sFieldClicked
on mouseup
if word 1 of the target is not "field" then pass mouseup
put ID of the target into sFieldClicked
Do_it
end mouseup
on Do_it
put space & "hello" after fld ID sFieldClicked
end Do_it
Kaveh
Re: Modifying field contents with script
kaveh1000 wrote: ↑Tue Aug 02, 2022 10:53 pmHi Craig
Great to have this interaction with you after a long time!
I take your points about the literal "hello". it was sloppy!
Did you see the minimal stack I uploaded? That answers your questions. I have 3 locked fields, yes. And the stack script is:
Code: Select all
local sFieldClicked on mouseup if word 1 of the target is not "field" then pass mouseup put ID of the target into sFieldClicked Do_it end mouseup on Do_it put space & "hello" after fld ID sFieldClicked end Do_it
except your 3 fields are not locked!
If you set the lockText of these fields to true then it works as you'd expect.
Did you mean to use unlocked fields for this? Sadly you cannot use mouse actions on unlocked fields, as mentioned above.
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Modifying field contents with script
Kaveh.
Good to talk to you as well.
Why do you have the "mouseUp" handler call another handler? Are the two examples just a small pair of snippets of a larger code set?
I see now what you meant with your comment about the "target" losing its "relevance" when the called handler does the work of actually doing the appending. You can pass that information along as a parameter, of course, or you can append the new text before you do the call, but again, do you need to do that at all?
Craig
Good to talk to you as well.
Why do you have the "mouseUp" handler call another handler? Are the two examples just a small pair of snippets of a larger code set?
I see now what you meant with your comment about the "target" losing its "relevance" when the called handler does the work of actually doing the appending. You can pass that information along as a parameter, of course, or you can append the new text before you do the call, but again, do you need to do that at all?
Craig
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Modifying field contents with script
Apologies. They should have been locked!except your 3 fields are not locked!
I am keeping it general as it's just a test for a bigger project. In the main project I need to call another handler from the mouseup handler. And as you say "target" is lost.Why do you have the "mouseUp" handler call another handler? Are the two examples just a small pair of snippets of a larger code set?
Main point is that I need to trap the ID of the target and keep it as a local parameter. Then I can call as many other handlers as needed.
I really appreciate the time of all on this as usual. Thanks again.
Regards
Kaveh
Kaveh
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Modifying field contents with script
I am sorry that my examples were off the point.
I will accept 50% of the responsibility for that.
The other 50% lies with you . . .
As Granny said, "A picture is worth a thousand words."
I will accept 50% of the responsibility for that.
The other 50% lies with you . . .
As Granny said, "A picture is worth a thousand words."
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: Modifying field contents with script
Richmond:
I will take 100% of blame because:
● I was OP
● I have learnt so much from you over the years.
I will take 100% of blame because:
● I was OP
● I have learnt so much from you over the years.
Kaveh