Welcome to the LimeSurvey Community Forum

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

Problem with starting a js script in a twig file

  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 10 months ago - 3 years 10 months ago #200607 by AuPath
Hello everyone,

I'm working on a survey where the objective is to record user mouse and gaze patterns.
To do this i'm using some custom js code and webgazer .

To start the recording of mouse and webcam data i put some js code in the question.twig file in a custom theme.

This works but obviously starts one time for every question loaded, so if i have two questions on screen my recording script starts twice and i have data duplication.

Is there someplace else where i could put this code? Maybe with the ability to start it only on certain questions? Can i put js code on specific questions without having to put code in template files?
Last edit: 3 years 10 months ago by AuPath.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #200620 by tpartner
Yes, why not simply place the code in the source of a question.

Or, if using frequently, place the code in a function in your custom.js file and call that function from within the source of questions.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 10 months ago #200671 by AuPath
How do i put code in the source of a question?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #200672 by tpartner

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 10 months ago - 3 years 10 months ago #200675 by AuPath
When i set "Filter HTML for XSS" to "Off" and then save, the "Filter HTML for XSS" option returns to "On"
Last edit: 3 years 10 months ago by AuPath.
The topic has been locked.
  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 10 months ago #200677 by AuPath
Nevermind i did it like 10 times in a row until it took
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #200678 by tpartner
What LimeSurvey version are you using?

If you are logged in as super-admin, the filter is bypassed anyway.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 10 months ago #200680 by AuPath
Version 4.1.7+200224
The topic has been locked.
  • AuPath
  • AuPath's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 10 months ago #200704 by AuPath
I got most of my script working but for some reason it seems like the function JSON.stringify does not work when i put in in the source of a question.

Any ideas why? It worked when it was in a twig file and the code is correct, i checked it.
Code:
JSON.stringify({'sid': 1, 'rid': 2, 'qid': 3, 'x': 4, 'y': 4, 'timestamp': new Date().getTime()});

This is the error:

Uncaught SyntaxError: Unexpected token '<'
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 10 months ago #200715 by tpartner
When using curly braces in question source, you need to insert a space or line-break after the opening brace and before the closing brace to prevent Expression Manager from parsing it.

Code:
JSON.stringify({
  'sid': 1, 
  'rid': 2, 
  'qid': 3, 
  'x': 4, 
  'y': 4, 
  'timestamp': new Date().getTime()
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose