Field without return chars

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

Post Reply
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Field without return chars

Post by MaxV » Tue Mar 18, 2014 1:37 pm

Hi all,
I created a single line field. When I pasted some text in it, I didn't realize that I pasted more than one line. This led to several bugs...
What is the best practice to obtain a really one line field? I mean a field that can't contain more than one line.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Field without return chars

Post by bangkok » Tue Mar 18, 2014 1:43 pm

Code: Select all

replace CR with "" in field "myfield"
You might be confronted with other issues (for instance if your field contains text coming from various plateforms). In this case you could add :

Code: Select all

replace CRLF with "" in field "myfield"

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Field without return chars

Post by MaxV » Wed Mar 19, 2014 12:35 pm

Ok, you suggestion is to modify the string.
What is the best message to do it? During typing? Losing focus? With paste?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

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

Re: Field without return chars

Post by Klaus » Wed Mar 19, 2014 1:07 pm

Hi Max,

you could add a little "intelligence" to the field like this in the fields script:

Code: Select all

## Prevent any new line characters in field:
on returninfield
  ##
end returninfield

## Same here:
on enterinfield
  ##
end enterinfield

## "Trap" the PASTEKEY
## Hint, this does not work in the IDE out of the box, please read the dictionary about "Pastekey"!
on pasteKey -- replace returns with spaces before pasting
  if the clipboardData["text"] <> empty then
    set the clipboardData["text"] to replaceText(the clipboardData["text"],return,space)
    paste
  end if
end pastekey
That should cover all possible scenarios.


Best

Klaus

Post Reply