Formula on a 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
captainbiblio
Posts: 3
Joined: Sat Feb 25, 2017 1:01 am

Formula on a field

Post by captainbiblio » Sat Feb 25, 2017 1:32 am

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".

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Formula on a field

Post by Dixie » Sat Feb 25, 2017 7:07 am

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...

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
dixie

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9706
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Formula on a field

Post by dunbarx » Sun Feb 26, 2017 4:48 pm

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

captainbiblio
Posts: 3
Joined: Sat Feb 25, 2017 1:01 am

Re: Formula on a field

Post by captainbiblio » Tue Feb 28, 2017 7:42 am

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9706
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Formula on a field

Post by dunbarx » Tue Feb 28, 2017 7:01 pm

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:

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
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

captainbiblio
Posts: 3
Joined: Sat Feb 25, 2017 1:01 am

Re: Formula on a field

Post by captainbiblio » Tue Feb 28, 2017 11:23 pm

Thanks. This works (when clicking - but not on hitting Enter key).

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9706
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Formula on a field

Post by dunbarx » Tue Feb 28, 2017 11:25 pm

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”