- 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
- Omti90
- Topic Author
- Offline
- Junior Member
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.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10104
- Thank you received: 3593
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10104
- Thank you received: 3593
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.
- Omti90
- Topic Author
- Offline
- Junior Member
- Posts: 23
- Thank you received: 2
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.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10104
- Thank you received: 3593
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.
- Omti90
- Topic Author
- Offline
- Junior Member
- Posts: 23
- Thank you received: 2
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.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10104
- Thank you received: 3593
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- Omti90
- Topic Author
- Offline
- Junior Member
- Posts: 23
- Thank you received: 2
Thank you. I had a look at it with the developer tools and the reason seems to be that the label "new-Text" simply isn't affected by the css (there is no entry for the css, as opposed to the wrapper elements).tpartner wrote: You can explore the DOM and styles with your browser developer tools (F12) to see what is affecting various elements.
Do I need to connect my div class in the twig and the css somehow? It seems to be done pretty much exactly as the original div classes, but my version isn't affected by the CSS. Any idea what I'm missing?
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10104
- Thank you received: 3593
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- ollehar
- Offline
- LimeSurvey GmbH Employee
- Posts: 522
- Thank you received: 108
- Omti90
- Topic Author
- Offline
- Junior Member
- Posts: 23
- Thank you received: 2
I tried that, also tried changing the browser, but it remains unaffected. I'm not sure what I need to do to make some class in the twig use the styling I've defined in the css.tpartner wrote: Completely clear the browser cache and refresh?
I figured I'd just have to use the same names in the twig and the css, but that doesn't seem to be the case.
This is how it looks in the developer tools for my custom class I've renamed into "aslfo" just in case that the "new" or "Text" in "new-Text" were some predefined keywords that were mucking everything up (that doesn't seem to be the case).
As you can see the custom class isn't affected by the style I've defined in the cardsort.css.
.card-sort-question .aslfo {
padding-bottom: 5px;
background: #db1313;
font-size: 110%;
font-weight: bold;
/*position: absolute;
width: 20%;
max-width: 340px;
height: 120px;
border: 2px solid rgb(19, 170, 64);
background: #db1313;*/
}
I'm quite stumped what I'm missing here. What do I need to do to make the class I'm defining in the twig use the styling from the css?
{% set names = question_template_attribute.area_names|split(',') %}
{% set labels = question_template_attribute.columnLabel|split(',') %}
{% set columns = question_template_attribute.columnCount %}
<div class="card-sort-outer-wrapper">
<div class="droppable items-start"></div>
{% for myIndex, ind in labels %}
<div class ="aslfo">
{{ind}}
</div>
{% endfor %}
<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>
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10104
- Thank you received: 3593
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.