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
-
golive
- Posts: 98
- Joined: Wed Jul 01, 2015 5:16 am
Post
by golive » Mon Sep 21, 2015 8:18 am
When typing into a field, how can I automatically capitalize the first letter
Example:
The user types:
car seat cover.
I want it to show as:
Car seat cover.
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Mon Sep 21, 2015 8:39 am
Hi golive,
Just use toUpper toLower functions
Code: Select all
put "car seat cover." into tMystring
put toUpper(char 1 of tMystring) into char 1 of tMystring
put tMystring
Best regards
Jean-Marc
https://alternatic.ch
-
golive
- Posts: 98
- Joined: Wed Jul 01, 2015 5:16 am
Post
by golive » Mon Sep 21, 2015 8:42 am
jmburnod wrote:Hi golive,
Just use toUpper toLower functions
Code: Select all
put "car seat cover." into tMystring
put toUpper(char 1 of tMystring) into char 1 of tMystring
put tMystring
Best regards
Jean-Marc
Thanks for your reply. I would like to do it live; while the user is typing in the first c, it changes it to C and carries on accepting the rest of the input.
This is what I tried (but it doesn't work):
Code: Select all
local sFirst
put false into sFirst
on keyDown tCharacter
if not sFirst then
put toUpper(tCharacter) into tCharacter
put true into sFirst
else
pass keyDown
end if
end keyDown
-
richmond62
- Livecode Opensource Backer

- Posts: 10100
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Mon Sep 21, 2015 9:06 am
I'm not sure how helpful this is, but I have just knocked together a wee stack called "Kapital" [attached here]
that contains a textField "feeld" and a cardScript:
on keyDown KEE
put toUpper (KEE) after fld "feeld"
end keyDown
I hope it is of some use.
-
Attachments
-
- Kapital.livecode.zip
- test stack
- (633 Bytes) Downloaded 242 times
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Mon Sep 21, 2015 9:15 am
Hi golive
What doesn't work ?
Is this better for you ?
Code: Select all
on keyDown tCharacter
get the num of chars of fld "MyField"
if it = 0 then
put toUpper(tCharacter) into fld "MyField"
select after field "myField"
else
pass keyDown
end if
end keyDown
Jean-Marc
https://alternatic.ch
-
richmond62
- Livecode Opensource Backer

- Posts: 10100
- Joined: Fri Feb 19, 2010 10:17 am
Post
by richmond62 » Mon Sep 21, 2015 9:31 am
That solution certainly seems OK IFF you want to capitalise the first letter of the whole text.
It might be a bit more complicated if you want to capitalise the first letter of ALL the words in the field.
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Sep 21, 2015 1:58 pm
I think the OP wants to capitalize only the first letter of the entire body of text. But then what happens if the user types a period? Does that trigger another round?
In any case, golive, Jean-Marc's post gives you a hint. You already know about how to make the "keyDown" message work for you.
Craig Newman
-
golive
- Posts: 98
- Joined: Wed Jul 01, 2015 5:16 am
Post
by golive » Tue Sep 22, 2015 2:51 am
jmburnod wrote:Hi golive
What doesn't work ?
Is this better for you ?
Code: Select all
on keyDown tCharacter
get the num of chars of fld "MyField"
if it = 0 then
put toUpper(tCharacter) into fld "MyField"
select after field "myField"
else
pass keyDown
end if
end keyDown
Jean-Marc
Yes thanks.
However, there is still an issue.
Type in something. Delete it, then type again. All good so far.
Now type in something. Select it by double-clicking. Now type in something new. It doesn't work anymore; does not capitalize the first letter.
Why?
Here is a stack to test it:
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Tue Sep 22, 2015 6:25 am
Hi golive,
try
Code: Select all
on keyDown tCharacter
if word 2 of the selectedChunk = 1 then
put toUpper(tCharacter) into fld "fldCapFirst"
select after field "fldCapFirst"
else
pass keyDown
end if
end keyDown
selectedChunk -> dictionary
I would play around with it a bit to get familiar with selectedChunk.
Kind regards
Bernd
-
golive
- Posts: 98
- Joined: Wed Jul 01, 2015 5:16 am
Post
by golive » Wed Sep 23, 2015 1:06 am
bn wrote:
selectedChunk -> dictionary
I would play around with it a bit to get familiar with selectedChunk.
Hi Bernd
Very good!
I would not have found selectedChunk without you, thanks
