Page 1 of 1
Text Boxes formatting text
Posted: Mon Apr 30, 2018 10:14 pm
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
Re: Text Boxes formatting text
Posted: Mon Apr 30, 2018 10:25 pm
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
Re: Text Boxes formatting text
Posted: Tue May 01, 2018 9:44 am
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
Re: Text Boxes formatting text
Posted: Tue May 01, 2018 2:23 pm
by Klaus
Hi Richard,
welcome to the forum!
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
Re: Text Boxes formatting text
Posted: Tue May 01, 2018 3:02 pm
by 1RichardClarke
Hi Kurt,
Thanks for the welcome
OK that makes sense, thanks for the help.
Will try and work the rest out
Richard
Re: Text Boxes formatting text
Posted: Tue May 01, 2018 3:45 pm
by Klaus
OH, COME ON!

Re: Text Boxes formatting text
Posted: Tue May 01, 2018 3:53 pm
by bogs
Klaus, you must have the single most mangle-able name on the net

Re: Text Boxes formatting text
Posted: Tue May 01, 2018 4:16 pm
by 1RichardClarke
sorry
Richard
Re: Text Boxes formatting text
Posted: Tue May 01, 2018 5:27 pm
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:
He knows this. He just forgot.
Craig
Re: Text Boxes formatting text
Posted: Tue May 01, 2018 5:36 pm
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!

Re: Text Boxes formatting text
Posted: Tue May 01, 2018 6:05 pm
by dunbarx
Ah.
Some numbers but not all of them. I see. Uh huh. Well, at least your number set was of infinite length.
Craig
Re: Text Boxes formatting text
Posted: Tue May 01, 2018 6:10 pm
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
Re: Text Boxes formatting text
Posted: Wed May 02, 2018 11:47 am
by 1RichardClarke
Hi Craig,
Yes i would appreciate some help with that, thanks
Richard
Re: Text Boxes formatting text
Posted: Wed May 02, 2018 7:19 pm
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
Re: Text Boxes formatting text
Posted: Thu May 03, 2018 9:37 am
by 1RichardClarke
Hi Craig,
Thanks for the pointers, will report back
Richard