Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

prevent CR/LF in text input

  • orvil
  • orvil's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
9 years 3 months ago - 9 years 3 months ago #115276 by orvil
prevent CR/LF in text input was created by orvil
Hi there,

I'd like to prevent the input of a carriage return/line feed and may be some other characters like "§", "$" and "&" within free text answers. Especially CR/LF is a nuisance exporting the survey results into a csv file.

Any ideas for solutions?

THX in advance!

Best regards/Beste Grüße,
O. Villani
Last edit: 9 years 3 months ago by orvil.
The topic has been locked.
  • c_schmitz
  • c_schmitz's Avatar
  • Offline
  • LimeSurvey GmbH Employee
  • LimeSurvey GmbH Employee
More
9 years 3 months ago #115277 by c_schmitz
Replied by c_schmitz on topic prevent CR/LF in text input
Hi Orvil,
Can you explain why it is a problem, what software do you use to parse it? It is a regular CSV format.

Best regards

Carsten Schmitz
LimeSurvey project leader
The topic has been locked.
  • orvil
  • orvil's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
9 years 3 months ago #115279 by orvil
Replied by orvil on topic prevent CR/LF in text input
Hi,

I have to import the csv into excel. The problem is, that the linefeeds are always starting a new row in excel, even if the single cell data and the CRLF is within quotation marks.

So eg a csv dataline like "1234","This is text with CRLF exactly here","42" (where the CR/LF where its written in the text) will lead to a table with 2 lines:
1235This is text with
exactly here42

Additionally: I want to prevent respondents to edit some other characters like said before. Only a-z,A-Z,0-9, space, minus, plus, colon, comma and semicolon and may be a few other characters should be editable from the beginning on.
By the way: Validation would be another method, but its only my third choice due to survey usability.

Best regards/Beste Grüße,
O. Villani
The topic has been locked.
  • orvil
  • orvil's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
9 years 3 months ago #115286 by orvil
Replied by orvil on topic prevent CR/LF in text input
Hmm,

found a first solution by using JS/jQuery. Looks like this:
Code:
<script type="text/javascript">
 
jQuery(document).ready(function() {
   jQuery(document).bind('keypress', function(e){
 
       if (e.which == 13) return false; // kills enter-key event, can be replaced by any key code
   })
});
 
</script>

Has to be placed within the question text field as usual.

@Carsten Schmitz:
I'm wondering if it would'nt be very usefull to have an on field for JS code in the backend (in addition to the question-text and help-text fields)
There are some advantages for this:
1. clean and separated code / question text
2. code can be always visible to the editor (not only in sourcecode mode)
3. security and rights: eventually only dedicated persons can be allowed to see/edit js code

Any ideas for a better solution than mine above? (the disadvantage of this solution is: canceled keys are canceled for the whole question page or all questions if more than one is visible at the same time)
Any comments to the idea of an extra js-code field for the backend?

THX

Best regards/Beste Grüße,
O. Villani
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 months ago #115296 by tpartner
Replied by tpartner on topic prevent CR/LF in text input

...the disadvantage of this solution is: canceled keys are canceled for the whole question page or all questions if more than one is visible at the same time...

Try this:

Code:
<script type="text/javascript">
 
jQuery(document).ready(function() {
   jQuery('#question{QID} textarea').bind('keypress', function(e){
 
       if (e.which == 13) return false; // kills enter-key event, can be replaced by any key code
   })
});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 months ago #115299 by DenisChenu
Replied by DenisChenu on topic prevent CR/LF in text input
Hi,

With ast version, cr/lf on text question type show mutiline cell in excel. If not, you can make a bug report :).

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
9 years 3 months ago #115334 by Mazi
Replied by Mazi on topic prevent CR/LF in text input
That is probably not a bug or Limesurvey issue but stupid Excel not being able to deal with CSV files properly.
MS Excel doesn't even stick to CSV standard and is famous for breaking CSV files on save.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose