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 »

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: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Text Boxes formatting text

Post by dunbarx »

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 »

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: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Text Boxes formatting text

Post by Klaus »

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 »

Hi Kurt,

Thanks for the welcome :)

OK that makes sense, thanks for the help.

Will try and work the rest out :)

Richard
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Text Boxes formatting text

Post by Klaus »

1RichardClarke wrote: Tue May 01, 2018 3:02 pm Hi Kurt,...
OH, COME ON! 8)
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Text Boxes formatting text

Post by bogs »

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 »

sorry :oops:

Richard
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Text Boxes formatting text

Post by dunbarx »

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: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Text Boxes formatting text

Post by Klaus »

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: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Text Boxes formatting text

Post by dunbarx »

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: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Text Boxes formatting text

Post by dunbarx »

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 »

Hi Craig,

Yes i would appreciate some help with that, thanks

Richard
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Text Boxes formatting text

Post by dunbarx »

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 »

Hi Craig,

Thanks for the pointers, will report back :)

Richard
Post Reply