Formula on a field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 3
- Joined: Sat Feb 25, 2017 1:01 am
Formula on a field
Is it possible to apply a formula on a field which will truncate the article in front of a word or group of words and then capitalize the first letter of the next word automatically ?
For example, if a user types "The big mountain" in the field then - after pressing the enter key - the field will change to show "Big mountain" instead of "The Big mountain".
For example, if a user types "The big mountain" in the field then - after pressing the enter key - the field will change to show "Big mountain" instead of "The Big mountain".
-
- Livecode Opensource Backer
- Posts: 1336
- Joined: Sun Jul 12, 2009 10:53 am
- Location: Bordeaux, France
Re: Formula on a field
This script will work for the example you have given... of course if there are other words that you wish to delete, then you will have to buid a list and check if they are contained in the list....
put in your field script...
dixie
put in your field script...
Code: Select all
on parseText
put the text of me into theFieldText
if word 1 of theFieldText = "the" then delete word 1 of theFieldText
put toUpper( char 1 of word 1 of theFieldText) into char 1 of word 1 of theFieldText
put theFieldText into me
end parseText
on enterinfield
parseText
end enterInField
-
- VIP Livecode Opensource Backer
- Posts: 9742
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Formula on a field
I think you can expand Dixie's idea so that any first word would be deleted, not just "the". I do not know if that is what you explicitly intended.
Also, the user might use other means to terminate text entry, such as tabbing out, using the return key, or others. In such cases, it may well be worth looking at the "exitField" or "closeField" messages.
Craig Newman
Also, the user might use other means to terminate text entry, such as tabbing out, using the return key, or others. In such cases, it may well be worth looking at the "exitField" or "closeField" messages.
Craig Newman
-
- Posts: 3
- Joined: Sat Feb 25, 2017 1:01 am
Re: Formula on a field
I pasted the code onto the code screen for a field, clicked "apply" (and saw "no errors").
But when I tested it my sentence "The big house" did not change at all.
Also it acted as if word wrap was on although I checked "don't wrap" in the inspector.
Any suggestions would be welcome because I am completely new to LiveCode. Thanks.
But when I tested it my sentence "The big house" did not change at all.
Also it acted as if word wrap was on although I checked "don't wrap" in the inspector.
Any suggestions would be welcome because I am completely new to LiveCode. Thanks.
-
- VIP Livecode Opensource Backer
- Posts: 9742
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Formula on a field
Hi.
I did not go into either Dixie's handler or your issue with it. I bet it is a message thing as opposed to a code thing. Anyway,
Make a new field on a new card. Put this into the field script:
Type int the field (with a leading "the", I presume) and then click somewhere else. Now there may be other things you want to do here, and other ways the user might terminate text entry. For example, you simply must learn how the "exitField" message is invoked. That is all on you.
Craig
I did not go into either Dixie's handler or your issue with it. I bet it is a message thing as opposed to a code thing. Anyway,
Make a new field on a new card. Put this into the field script:
Code: Select all
on closeField
if word 1 of me = "the" then
delete word 1 of me
put toUpper( char 1 of word 1 of me) into char 1 of word 1 of me
end if
end closeField
Craig
-
- Posts: 3
- Joined: Sat Feb 25, 2017 1:01 am
Re: Formula on a field
Thanks. This works (when clicking - but not on hitting Enter key).
-
- VIP Livecode Opensource Backer
- Posts: 9742
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Formula on a field
Remember that "this is on you" thing.
So what you are essentially saying is that you have not trapped the "enterInField" message. Might that lead you somewhere?
You can do this...
Craig
So what you are essentially saying is that you have not trapped the "enterInField" message. Might that lead you somewhere?
You can do this...
Craig