Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 262
Registered: ‎05-18-2011
My Device: Curve 9300, BB10 Dev Alpha C, Z10

How to capitalize first letter of each word in a TextField in qml

[ Edited ]

Hi guys,

 

I can't find any textinputflags that auto capitalize first letter of each word in a TextField. Please share if you have a script function that can be used for this purpose on a qml. I'd like a solution that works with any langages.

 

Thanks,

--tom
Developer
Posts: 1,022
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: How to capitalize first letter of each word in a TextField in qml

AFAIK there is no built in function to do this. I would probably do it by setting the TextFieldInputMode to Custom and processing the key strokes myself. If you build a custom key stoke handler class you could add a member variable holding exception words so you could capitalize everything EXCEPT those words, such as "a", "the", "of", etc. This is commonly called Proper format.

 

If you want it to support different exception words depending on Locale/Langauge you can coopt the Translation engine by putting your exception word string inside qsTr() (QML) or tr() (C++).



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Retired
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: How to capitalize first letter of each word in a TextField in qml

Hi, 

 

I think this does what you're looking for...

 



TextField { id: t onTextChanging: { var newText = text.replace(/(\s|^)(\S)/g, function caps(a, p1, p2) { return p1+p2.toUpperCase(); }); if (newText != text) { t.text = newText; } } }

 

Thanks!

 

--
Rob is no longer associated with BlackBerry.
Developer
Posts: 262
Registered: ‎05-18-2011
My Device: Curve 9300, BB10 Dev Alpha C, Z10

Re: How to capitalize first letter of each word in a TextField in qml

Thanks greenmr and robbieDubya. I think I will try robbieDubya's suggestion first.

Thanks,
--tom
Developer
Posts: 1,022
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: How to capitalize first letter of each word in a TextField in qml

No worries. I actually like that suggestion better too. I was actually going to suggest something similar at first, till I noticed that the text parameter was marked as const and was thinking you wouldn't be able to alter it's value. After I posted I realized that just means you can't change the parameter to point at something else, but you can alter the value of the QString that it points to.

 

By that time it was too late. ;-)



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.