Prevent user pasting CR LF

Prevent user pasting CR LF

Postby hua » Fri Oct 09, 2015 10:15 am

Guys,

I occasionally come across in user's data, CRLF (\r\n) tacked at the end of the field value. Below is one such example
Image

I suspect this occur when user copy and paste from documents such as Word or Excel into my FWH program. Is there any way to prevent this from happening?

TIA
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Prevent user pasting CR LF

Postby James Bott » Fri Oct 09, 2015 4:05 pm

Maybe use bChange to use a codeblock to strip out and CR and LFs?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Prevent user pasting CR LF

Postby Armando » Fri Oct 09, 2015 5:11 pm

Hua:

At the moment I do not remember if there is a function to remove the CRLF,
any way you can try the following sample code:

Code: Select all  Expand view  RUN

cString := "This is a string + CRLF " + CRLF

MsgInfo(LEN(cString))
cString := STRTRAN(cString,CRLF,"")
MsgInfo(LEN(cString))
 


Please use this code in the VALID clause of your GET

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3242
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Prevent user pasting CR LF

Postby James Bott » Fri Oct 09, 2015 5:18 pm

I just found that there is a bPaste codeblock you should be able to use also. Unlike bChange or VALID this codeblock will only be called when pasting.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Prevent user pasting CR LF

Postby hua » Fri Oct 09, 2015 11:21 pm

Thanks Armando and James.

Armando, I don't think it's practical to modify the source to sanitize input at VALIDs. There are a lots of them because ideally all gets should strip any formatting information.

Thanks for pointing out bPaste James. Maybe I could try to customize TGet so all of my gets will sanitize pasted input using bPaste.

Antonio, I hope FWH can come up with a built-in mechanism to strip-off formatting when text is pasted. Much like how a text editor behave where whatever we pasted only the text sticks not the control characters/formatting.
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Prevent user pasting CR LF

Postby James Bott » Sat Oct 10, 2015 3:51 pm

Hua,

Antonio, I hope FWH can come up with a built-in mechanism to strip-off formatting when text is pasted. Much like how a text editor behave where whatever we pasted only the text sticks not the control characters/formatting.


I think it would have to be optional, since sometimes we want control characters and formatting, such as in multi-line text fields. It could be complicated in apps where you want both behaviors.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Prevent user pasting CR LF

Postby Armando » Sat Oct 10, 2015 4:23 pm

Hua:

I agree with you when there are many GETs , it occurs to me to make a global function
with my suggestion and in each GET call that function.

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3242
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Prevent user pasting CR LF

Postby James Bott » Sat Oct 10, 2015 4:46 pm

Armando,

Depending on how many GETs you have, it would probably be easier to modify the TGet class by adding a CLASSVAR to trigger stripping the CR and LF characters. A CLASSVAR is like a static, so if you default it to .t. then all GETs will be stripped. If you need a GET to not be stripped, then you just reset the CLASSVAR before entering the GET and reset it again when leaving the GET. There would be no changes to your app code--you only have to link in the modified GET class.

The only issue is when the stock TGet class is modified, then you need to move your changes to the new class.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Prevent user pasting CR LF

Postby Armando » Sat Oct 10, 2015 5:09 pm

James:

James Bott wrote:Armando,
Depending on how many GETs you have, it would probably be easier to modify the TGet class by adding a CLASSVAR to trigger stripping the CR and LF characters. A CLASSVAR is like a static, so if you default it to .t. then all GETs will be stripped. If you need a GET to not be stripped, then you just reset the CLASSVAR before entering the GET and reset it again when leaving the GET. There would be no changes to your app code--you only have to link in the modified GET class.
James

You're absolutely right.

James Bott wrote:The only issue is when the stock TGet class is modified, then you need to move your changes to the new class.
James

This is why I do not like to modify the clases, but it depends on each developer


With best regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3242
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: Prevent user pasting CR LF

Postby James Bott » Sun Oct 11, 2015 5:34 pm

Armando,

Another option is to create a TGet subclass. Then you would need to modify the FIVEWIN.CH file to call that subclass rather than the TGet class.

When a new version of FW comes out the only change you would have to make is to the CH file and probably that change would only be one word--the name of the TGet subclass.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Prevent user pasting CR LF

Postby Armando » Mon Oct 12, 2015 2:56 pm

James:

I think It's the best option.

Thanks a lots
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3242
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 102 guests