- Posts: 19
- Thank you received: 0
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
- Topic Author
- Offline
- New Member
Less
More
3 years 10 months ago - 3 years 10 months ago #200607
by AuPath
Problem with starting a js script in a twig file was created 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?
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
3 years 10 months ago #200620
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Problem with starting a js script in a twig file
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.
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
3 years 10 months ago #200671
by AuPath
Replied by AuPath on topic Problem with starting a js script in a twig file
How do i put code in the source of a question?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
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.
Replied by tpartner on topic Problem with starting a js script in a twig file
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
3 years 10 months ago - 3 years 10 months ago #200675
by AuPath
Replied by AuPath on topic Problem with starting a js script in a twig file
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
3 years 10 months ago #200677
by AuPath
Replied by AuPath on topic Problem with starting a js script in a twig file
Nevermind i did it like 10 times in a row until it took
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
3 years 10 months ago #200678
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Problem with starting a js script in a twig file
What LimeSurvey version are you using?
If you are logged in as super-admin, the filter is bypassed anyway.
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
3 years 10 months ago #200680
by AuPath
Replied by AuPath on topic Problem with starting a js script in a twig file
Version 4.1.7+200224
The topic has been locked.
- AuPath
- Topic Author
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
3 years 10 months ago #200704
by AuPath
Replied by AuPath on topic Problem with starting a js script in a twig file
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.
This is the error:
Uncaught SyntaxError: Unexpected token '<'
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10108
- Thank you received: 3593
3 years 10 months ago #200715
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Problem with starting a js script in a twig file
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.