- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Convert Long Free Text or Huge Free Text to Single Line
- statman13
- Topic Author
- Offline
- New Member
Less
More
7 years 2 months ago #148632
by statman13
Convert Long Free Text or Huge Free Text to Single Line was created by statman13
Hi
A very urgent question...
I have several Long Free Text fields containing newline/new paragraphs which I cannot convert to a single line using javascript:
var lorem='{LFTextItem.shown}';
Have tried several regex variants like
var lorem='{LFTextItem.shown}'.replace('/\r?\n/g', ' ');
I use splitTextToSize in jsPDF to print several lines of text in a pdf. It requires a single string input.
The script fails as soon as a Free Text field contains any new line characters.
Should I treat the item as a multidimensional array? If I look at the survey reply in the administrator interface, new line characters are automatically removed. How can I obtain the same effect in my javascript?
Can I use a REGEX inside the configuration of the item in Limesurvey to bypass these issues?
/statman13
A very urgent question...
I have several Long Free Text fields containing newline/new paragraphs which I cannot convert to a single line using javascript:
var lorem='{LFTextItem.shown}';
Have tried several regex variants like
var lorem='{LFTextItem.shown}'.replace('/\r?\n/g', ' ');
I use splitTextToSize in jsPDF to print several lines of text in a pdf. It requires a single string input.
The script fails as soon as a Free Text field contains any new line characters.
Should I treat the item as a multidimensional array? If I look at the survey reply in the administrator interface, new line characters are automatically removed. How can I obtain the same effect in my javascript?
Can I use a REGEX inside the configuration of the item in Limesurvey to bypass these issues?
/statman13
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
7 years 2 months ago #148685
by DenisChenu
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.
Replied by DenisChenu on topic Convert Long Free Text or Huge Free Text to Single Line
Think this can be done in PHP (then when click next only) using expression manager and
manual.limesurvey.org/Expression_Manager..._Assignment_Operator
Something like
{QCODE=str_replace("\n"," ",QCODE.NAOK)}
Else : did you try manual.limesurvey.org/Question_type_-_Lo...s_.28display_rows.29 to 1.
I move this topic toi general issue : not a dev issue
Something like
{QCODE=str_replace("\n"," ",QCODE.NAOK)}
Else : did you try manual.limesurvey.org/Question_type_-_Lo...s_.28display_rows.29 to 1.
I move this topic toi general issue : not a dev issue
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.
- statman13
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
7 years 2 months ago - 7 years 2 months ago #148839
by statman13
Replied by statman13 on topic Convert Long Free Text or Huge Free Text to Single Line
Hi Denis
It *is* possible to convert a long free text answer to a short free text answer, using the 'hide' option.
However there are issues updating the answer if the respondent types in a new answer in the long free text box.
The php function you suggested will not give the desired result using an equation type hidden question.
I also tried javascript in vain. Since referenced long free text fields come up without carriage return or newline characters in question text, but not in default answer texts, there must be a way to get around this problem, using either PHP or javascript...
... by the way ... converting a long free text answer to a short free text answer is possible on a platform using MySQL only due to 256 character limitations in Postgres / MS SQL!
/statman13
It *is* possible to convert a long free text answer to a short free text answer, using the 'hide' option.
However there are issues updating the answer if the respondent types in a new answer in the long free text box.
The php function you suggested will not give the desired result using an equation type hidden question.
I also tried javascript in vain. Since referenced long free text fields come up without carriage return or newline characters in question text, but not in default answer texts, there must be a way to get around this problem, using either PHP or javascript...
... by the way ... converting a long free text answer to a short free text answer is possible on a platform using MySQL only due to 256 character limitations in Postgres / MS SQL!
/statman13
Last edit: 7 years 2 months ago by statman13.
The topic has been locked.
- statman13
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
7 years 1 month ago #148901
by statman13
Replied by statman13 on topic Convert Long Free Text or Huge Free Text to Single Line
Use of the php function addslashes({FreeTextItemName}) in a hidden Equation Item under Advanced Options is a solution if you want to coerce the inputted text from a Free Text item to a string.
Use the processed expression in a question group separate from the original free text item, and put the equation item at the end of the question group of the original free text item.
The coercion is a basic consequence of the use of a PHP call just like echoing the content of a variable to a html body text.
Use the processed expression in a question group separate from the original free text item, and put the equation item at the end of the question group of the original free text item.
The coercion is a basic consequence of the use of a PHP call just like echoing the content of a variable to a html body text.
The topic has been locked.