- Posts: 15
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Detect if question is answered
- flobau
- Topic Author
- Offline
- New Member
Less
More
5 years 1 day ago - 5 years 1 day ago #183723
by flobau
Replied by flobau on topic Detect if question is answered
Thanks for your answer. This seems to be true everytime. Even when the question isn't answered yet.
Both of the if's equal to 'true' and the content is shown for both.
Code:
{% if(processString("{is_empty(self)}")) %} <div class="{{ aSurveyInfo.class.questionasterix }} pull-left" {{ aSurveyInfo.attr.questionasterix }} > <small style="margin-right: 3px; font-size: 65%;" class="{{ aSurveyInfo.class.questionasterixsmall }} text-danger fa fa-asterisk small" {{ aSurveyInfo.attr.questionasterixsmall }}></small> <span class="{{ aSurveyInfo.class.questionasterixspan }} sr-only text-danger" {{ aSurveyInfo.attr.questionasterixspan }} > {{ gT("(This question is mandatory)") }} </span> </div> {% endif %} {% if(processString("{!is_empty(self)}")) %} <div class="{{ aSurveyInfo.class.questionasterix }} pull-left" {{ aSurveyInfo.attr.questionasterix }} > {{ image('./files/haken.png', 'Question answered') }} </div> {% endif %}
Both of the if's equal to 'true' and the content is shown for both.
Last edit: 5 years 1 day ago by flobau.
The topic has been locked.
- flobau
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
5 years 1 day ago - 5 years 1 day ago #183734
by flobau
Replied by flobau on topic Detect if question is answered
I now tried multiple variables of aQuestion, but there seems to be no indication variable if a question has been answered. Do you guys have any ideas for another approach? Maybe with JavaScript?
Last edit: 5 years 1 day ago by flobau.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
5 years 1 day ago - 5 years 1 day ago #183737
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 Detect if question is answered
Right … it get it when loadong and don't update it …
Can do like that :
Can do like that :
Code:
{{ processString("{if(is_empty(self.NAOK),'<span class=\"text-danger\">Mandatory question not answered</span>',' <span class=\"text-success\">question answered</span>')}") }}
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.
Last edit: 5 years 1 day ago by DenisChenu.
The topic has been locked.
- flobau
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
5 years 1 day ago #183739
by flobau
Replied by flobau on topic Detect if question is answered
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
5 years 1 day ago #183744
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 Detect if question is answered
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.
- flobau
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
5 years 1 day ago #183746
by flobau
Replied by flobau on topic Detect if question is answered
works with
now, however it is not updating when a user answeres a question.
Code:
{{ processString("{if(count(self.NAOK)>0,'<span>Mandatory question answered</span>',' <span>question not answered</span>')}") }}
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
5 years 1 day ago - 5 years 1 day ago #183751
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 Detect if question is answered
Where did yout put this code ?
Proof of concept
Proof of concept
Code:
{{ processString("{if(count(self.NAOK),' <span class=\"text-success\">'+count(self.NAOK)+' questions answered</span>','<span class=\"text-danger\">No question answered</span>')}") }}
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.
Last edit: 5 years 1 day ago by DenisChenu.
The topic has been locked.
- flobau
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
5 years 1 day ago #183752
by flobau
Replied by flobau on topic Detect if question is answered
inside the
file.
Code:
question_text_content.twig
Code:
{% if aQuestion.mandatory != '' %} {{ processString("{if(count(self.NAOK)>0,'<span>Mandatory question answered</span>',' <span>question not answered</span>')}") }} <div class="{{ aSurveyInfo.class.questionasterix }} pull-left" {{ aSurveyInfo.attr.questionasterix }} > <small style="margin-right: 3px; font-size: 65%;" class="{{ aSurveyInfo.class.questionasterixsmall }} text-danger fa fa-asterisk small" {{ aSurveyInfo.attr.questionasterixsmall }}></small> <span class="{{ aSurveyInfo.class.questionasterixspan }} sr-only text-danger" {{ aSurveyInfo.attr.questionasterixspan }} > {{ gT("(This question is mandatory)") }} </span> </div> {% endif %}
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
5 years 1 day ago #183753
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 Detect if question is answered
Seems there are an issue with count and integer comparaison ?
Need time to check, what happen if you put this inside question text ?
Maybe related to this issue : bugs.limesurvey.org/view.php?id=14198
Need tracking
Need time to check, what happen if you put this inside question text ?
Maybe related to this issue : bugs.limesurvey.org/view.php?id=14198
Need tracking
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.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
5 years 18 hours ago - 5 years 18 hours ago #183794
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 Detect if question is answered
I cannot get the Twig/EM variable to update dynamically either.
Here is a JavaScript solution that could be placed in question_text_content.twig.
Note that this is only for mandatory list-radio, list-dropdown, multiple-choice, short-text and long-text questions. It would have to be extended to work in arrays, multiple-short-text, multiple-numeric, ranking, etc.
Here is a JavaScript solution that could be placed in question_text_content.twig.
Note that this is only for mandatory list-radio, list-dropdown, multiple-choice, short-text and long-text questions. It would have to be extended to work in arrays, multiple-short-text, multiple-numeric, ranking, etc.
Code:
<script type="text/javascript" charset="utf-8"> function checkAnswered(thisQuestion) { $('.answered-tip', thisQuestion).hide(); var answered = false; if($('input:radio:visible:checked, input:checkbox:visible:checked', thisQuestion).length > 0) { answered = true; } if($('select:visible, input:text:visible, textarea:visible', thisQuestion).filter(function() { return $.trim($(this).val()) != ''; }).length > 0) { answered = true; } if(answered == true) { $('.answered-tip.answered', thisQuestion).show(); } else { $('.answered-tip.unanswered', thisQuestion).show(); } } $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var thisQuestion = $('#question{{ aQuestion.qid }}'); // Initial state checkAnswered(thisQuestion); // Listener on the inputs $('input:visible, select:visible, textarea:visible', thisQuestion).on('click change keyup', function(e) { checkAnswered(thisQuestion); }); }); </script> {# If the question is mandatory, the asterisk will be shown #} {% if aQuestion.mandatory != '' %} <span class="answered-tip answered">Mandatory question answered</span> <span class="answered-tip unanswered">Question not answered</span> <!-- Add a visual information + just Mandatory string for aria : can be improved --> <div class="{{ aSurveyInfo.class.questionasterix }} pull-left" {{ aSurveyInfo.attr.questionasterix }} > <small class="{{ aSurveyInfo.class.questionasterixsmall }} text-danger fa fa-asterisk small" {{ aSurveyInfo.attr.questionasterixsmall }}></small> <span class="{{ aSurveyInfo.class.questionasterixspan }} sr-only text-danger" {{ aSurveyInfo.attr.questionasterixspan }} > {{ gT("(This question is mandatory)") }} </span> </div> {% endif %}
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 18 hours ago by tpartner.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
5 years 15 hours ago - 5 years 15 hours ago #183821
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 Detect if question is answered
See the
proof of concept
: it work but not with whole condition …
Here the < 0 seems an issue.
I try to check same equation inside question text …
But it's really strange … bugs.limesurvey.org/view.php?id=14817
I must check with vanilla, not only skelvanilla too …
EDIT:
Checked with vanilla too …
Link to twig file
Here the < 0 seems an issue.
I try to check same equation inside question text …
But it's really strange … bugs.limesurvey.org/view.php?id=14817
I must check with vanilla, not only skelvanilla too …
EDIT:
Checked with vanilla too …
Link to twig file
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.
Last edit: 5 years 15 hours ago by DenisChenu.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
5 years 15 hours ago #183822
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 Detect if question is answered
Yo \o/
Got a working solution
Proof of concept
twig file
Got a working solution
Code:
{% set questionCount = processString("{count(self.question)}") %} {{ processString("{if(count(self.NAOK)== 0,'<span class=\"text-danger\">No question answered</span>')}") }} {{ processString("{if(count(self.NAOK) gt 0 and count(self.NAOK) lt "~questionCount~",'<span class=\"text-warning\">'+count(self.NAOK)+' question(s) answered</span>')}") }} {{ processString("{if(count(self.NAOK) == "~questionCount~",'<span class=\"text-success\">All questions answered</span>')}") }}
Proof of concept
twig file
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 following user(s) said Thank You: tpartner
The topic has been locked.