Page 1 of 1
Prevent user pasting CR LF
Posted:
Fri Oct 09, 2015 10:15 am
by hua
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
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
Re: Prevent user pasting CR LF
Posted:
Fri Oct 09, 2015 4:05 pm
by James Bott
Maybe use bChange to use a codeblock to strip out and CR and LFs?
James
Re: Prevent user pasting CR LF
Posted:
Fri Oct 09, 2015 5:11 pm
by Armando
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
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
Re: Prevent user pasting CR LF
Posted:
Fri Oct 09, 2015 5:18 pm
by James Bott
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
Re: Prevent user pasting CR LF
Posted:
Fri Oct 09, 2015 11:21 pm
by hua
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.
Re: Prevent user pasting CR LF
Posted:
Sat Oct 10, 2015 3:51 pm
by James Bott
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
Re: Prevent user pasting CR LF
Posted:
Sat Oct 10, 2015 4:23 pm
by Armando
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
Re: Prevent user pasting CR LF
Posted:
Sat Oct 10, 2015 4:46 pm
by James Bott
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
Re: Prevent user pasting CR LF
Posted:
Sat Oct 10, 2015 5:09 pm
by Armando
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
Re: Prevent user pasting CR LF
Posted:
Sun Oct 11, 2015 5:34 pm
by James Bott
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
Re: Prevent user pasting CR LF
Posted:
Mon Oct 12, 2015 2:56 pm
by Armando
James:
I think It's the best option.
Thanks a lots