- Posts: 23
- Thank you received: 2
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How to best start coding my own questions
I've been looking into creating custom question templates. Basically our questionaire is asking for dual or even triple Matrix questions, but I'm pretty sure if we try that our participants will boycott the survey.
So I want to try to turn that sort of matrix into a drag and drop question, like this example: github.com/tpartner/LimeSurvey-Card-Sorting-3.x
Card Sorting basically does already most of the things I want, it's just two dimensional and I need it to be a three dimensional matrix and it would be nice if one could use images rather than text cards.
So I figured maybe I can just code that sort of thing myself and I've been looking a bit, but I can't find any introduction into coding custom questions for limesurvey (I stumbled over coding custom themes with Twig but that isn't exacly what I want). Can anyone recommend some tutorial, or maybe just link the necessary documentation? Right now I'm a bit clueless where to start.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The card sorting question theme does work with images. Simply replace the sub-question text with image tags.Omti90 wrote: ...and it would be nice if one could use images rather than text cards.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Thank you very much, I did not realize there was a complext text editor for the sub-questions. That's making things a lot easier.tpartner wrote:
The card sorting question theme does work with images. Simply replace the sub-question text with image tags.Omti90 wrote: ...and it would be nice if one could use images rather than text cards.
Thank you again, this is explaining what the XML part does really well. From looking at the CardSorting code, I suppose the CSS is for styling the elements while the java script defines the drag and drop function and the twig makes the custom properties interact with the original theme.As far as I know, the only (limited) documentation is here - github.com/LimeSurvey/LimeSurvey/tree/master/themes/question
Now I managed to add two new attributes to the CardSort:
It doesn't take the inputtype number (I googled that, but apparently that's wrong), what do I need to make it accept only (natural) numbers? Also is there some way to restrict these numbers? Like from 1-5?<attribute>
<name>columnCount</name>
<category>Custom options</category>
<sortorder>90</sortorder>
<inputtype>number</inputtype>
<default>1</default>
<help>Sets the number of Columns that are to be displayed by the cardsorting</help>
<caption>Number of Columns </caption>
<i18n>en</i18n>
</attribute>
<attribute>
<name>columnLabel</name>
<category>Custom options</category>
<sortorder>90</sortorder>
<inputtype>text</inputtype>
<default>Answer</default>
<help>Sets the labels for the Columns</help>
<caption>Column Labels</caption>
<i18n>en</i18n>
</attribute>
So the next step for me would be to look for twig tutorials and then rewrite your cardsort.twig to make multiple columns of droppable items. Or would I need to define additional style elements in the css first?
Anyways, thank you very much for both your advise and your open source cardsort theme.
You could use <inputtype>integer</inputtype> but if values are limited to 1-5, I would use <inputtype>buttongroup</inputtype>....what do I need to make it accept only (natural) numbers? Also is there some way to restrict these numbers? Like from 1-5?
<attribute> <name>custom_attribute_2</name> <category>Custom options</category> <sortorder>1</sortorder> <inputtype>buttongroup</inputtype> <options> <one>1</one> <two>2</two> <three>3</three> <four>4</four> <five>5</five> </options> <default>three</default> <help>Just another test attribute...</help> <caption>Test attribute 2</caption> </attribute>
You will need to develop CSS in conjunction with the HTML elements introduced via TWIG or JavaScript.Or would I need to define additional style elements in the css first?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
I tried to create some custom text field in css with the script above and then show it using the following twig code..card-sort-question .new-Text
{
position: absolute;
width: 20%;
max-width: 340px;
height: 120px;
border: 2px solid rgb(19, 170, 64);
background: #db1313;
}
I added the orange lines. This does sort of work since it prints the "labels" about where I would expect them.{% set names = question_template_attribute.area_names|split(',') %}
{% set labels = question_template_attribute.columnLabel %}
{% set columns = question_template_attribute.columnCount %}
<div class="card-sort-outer-wrapper">
<div class="droppable items-start"></div>
<div class ="new-Text">{{labels}}</div>
<div class="items-end-wrapper">
{% for index, item in names %}
<div class="items-end-inner">
<div class="items-end-text">{{item|trim}}</div>
<div class="droppable items-end items-end-{{index+1}}" data-items-end="{{index+1}}"></div>
</div>
{% endfor %}
</div>
</div>
But for some reason, it doesn't appear in the styling stuff I put in the css. (Which is admittedly rather random, but I figured it'd show at least something) I assume I made some really basic and stupid mistake here, but I'm not sure what that might be.