Text Boxes formatting text

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
1RichardClarke
Posts: 6
Joined: Mon Apr 30, 2018 9:22 pm

Text Boxes formatting text

Post by 1RichardClarke » Mon Apr 30, 2018 10:14 pm

Hi,

I am evaluating LiveCode at the moment. Maybe I am missing something, but it seems like a lot of hard work if your application has a lot of numeric fields / fields that need to be upper case. I think this would be true of a lot of business applications.

As far as i can see he only way is to put code onto each field. Having coded once I can't see a way of saving these as a template, so each time you need to copy & paste the code. Guess you can put one of each type on the main stack, make them invisible and copy from there onto the other stacks.

Have I missed something, is there a better way of doing this?

Thanks.

Richard

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

Re: Text Boxes formatting text

Post by dunbarx » Mon Apr 30, 2018 10:25 pm

Hi.

It is simple and straightforward to place Title Text, or any other variant into a field. Further, user input can be reformatted live.

As for numeric input, again, that can be filtered live to ensure that only digits are allowed (or not allowed) as required. Validation of entered text is well established.

Further, it is probable that a single handler, placed in the message hierarchy "above" the fields on a card, or in a stack, can manage all of them.

Can you give an example of what you are trying to achieve, in plain english, so we can offer solutions? I promise that what we send back will make you smile.

Craig Newman

1RichardClarke
Posts: 6
Joined: Mon Apr 30, 2018 9:22 pm

Re: Text Boxes formatting text

Post by 1RichardClarke » Tue May 01, 2018 9:44 am

Hi,

For a numeric text box I want to be able to: -

1. set the number of decimal places
2. use the comma as a thousands separator
3. include a currency symbol, set a different background colour to the text box if the currency being used is different to the home currency.
4. If the number in the text box is zero display nothing rather than a zero.

the format of the text box needs to be set for the displaying and editing of data.

Thanks

Richard

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Text Boxes formatting text

Post by Klaus » Tue May 01, 2018 2:23 pm

Hi Richard,

welcome to the forum! :D

You can write re-usable code in LC with behaviours.

Simple example:
1. Create a button with this script, you can hide the button afterwards:

Code: Select all

on keydown tKey
  if tKey is in "0123456789" then
     pass keydown
  end if
end keydown
2. Now create a field and set its behavior to that button (Inspector for the field)
Et voila, that field will only accept numbers as imput.

This way you can attach this single script object to as many fields as you like.

Get the picture?


Best

Klaus

1RichardClarke
Posts: 6
Joined: Mon Apr 30, 2018 9:22 pm

Re: Text Boxes formatting text

Post by 1RichardClarke » Tue May 01, 2018 3:02 pm

Hi Kurt,

Thanks for the welcome :)

OK that makes sense, thanks for the help.

Will try and work the rest out :)

Richard

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Text Boxes formatting text

Post by Klaus » Tue May 01, 2018 3:45 pm

1RichardClarke wrote:
Tue May 01, 2018 3:02 pm
Hi Kurt,...
OH, COME ON! 8)

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Text Boxes formatting text

Post by bogs » Tue May 01, 2018 3:53 pm

Klaus, you must have the single most mangle-able name on the net :wink:
Image

1RichardClarke
Posts: 6
Joined: Mon Apr 30, 2018 9:22 pm

Re: Text Boxes formatting text

Post by 1RichardClarke » Tue May 01, 2018 4:16 pm

sorry :oops:

Richard

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

Re: Text Boxes formatting text

Post by dunbarx » Tue May 01, 2018 5:27 pm

Behaviors is also a good way to go, similar to a handler high up in the hierarchy.

Note that whichever way you implement this, you can discriminate among your fields, so that only the ones you designate will have either the handler or the behavior script "fire" when user entry is in progress.

Also, Klaus' offering should include a decimal point:

Code: Select all

"0123456789."
He knows this. He just forgot.

Craig

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Text Boxes formatting text

Post by Klaus » Tue May 01, 2018 5:36 pm

dunbarx wrote:
Tue May 01, 2018 5:27 pm
...
He just forgot.
...
No, I didn't!

I was just giving an example for forcing NON-floating point numbers! :D

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

Re: Text Boxes formatting text

Post by dunbarx » Tue May 01, 2018 6:05 pm

Ah.

Some numbers but not all of them. I see. Uh huh. Well, at least your number set was of infinite length. :wink:

Craig
Last edited by dunbarx on Tue May 01, 2018 9:06 pm, edited 1 time in total.

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

Re: Text Boxes formatting text

Post by dunbarx » Tue May 01, 2018 6:10 pm

Richard.

The above nonsense aside, do you need help with the other parts of your project? For example, the other four items you mentioned all require additional coding.

Craig

1RichardClarke
Posts: 6
Joined: Mon Apr 30, 2018 9:22 pm

Re: Text Boxes formatting text

Post by 1RichardClarke » Wed May 02, 2018 11:47 am

Hi Craig,

Yes i would appreciate some help with that, thanks

Richard

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

Re: Text Boxes formatting text

Post by dunbarx » Wed May 02, 2018 7:19 pm

Let's start using "field" instead of "text box". I never heard of a text box in LC until I met you.

#1- see the dictionary entry on "numberFormat" and also "format". Experiment and write back.

#2- This is a fun thing to do. Leave it for the moment.

#3- You can include chars such as "$" or "£' in your filtered data, and:

Code: Select all

if the text of field "yourField" contains "$" then set the backColor of field "yourField" to "red"
#4-

Code: Select all

if the text of field "yourField" = "0" then put "" into field "yourField"
Is #4 robust enough to cover all bases? I don't know. Try it with all kinds of user entry and backspacing.

Experiment with several fields on a card, Do the above, and write back. We will then do #2, and THEN, talk about those high level handlers and behaviors.

Craig

1RichardClarke
Posts: 6
Joined: Mon Apr 30, 2018 9:22 pm

Re: Text Boxes formatting text

Post by 1RichardClarke » Thu May 03, 2018 9:37 am

Hi Craig,

Thanks for the pointers, will report back :)

Richard

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”