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
  • Omti90's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago #211817 by Omti90
Hello,
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.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #211819 by tpartner
Replied by tpartner on topic How to best start coding my own questions
As far as I know, the only (limited) documentation is here - github.com/LimeSurvey/LimeSurvey/tree/master/themes/question

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu, Omti90
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #211822 by tpartner
Replied by tpartner on topic How to best start coding my own questions

Omti90 wrote: ...and it would be nice if one could use images rather than text cards.

The card sorting question theme does work with images. Simply replace the sub-question text with image tags.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Omti90
The topic has been locked.
  • Omti90
  • Omti90's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago - 3 years 2 months ago #211859 by Omti90
Replied by Omti90 on topic How to best start coding my own questions

tpartner wrote:

Omti90 wrote: ...and it would be nice if one could use images rather than text cards.


 

The card sorting question theme does work with images. Simply replace the sub-question text with image tags.





 

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.

As far as I know, the only (limited) documentation is here - github.com/LimeSurvey/LimeSurvey/tree/master/themes/question

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.

Now I managed to add two new attributes to the CardSort:

<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>

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?

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.
Last edit: 3 years 2 months ago by Omti90.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago - 3 years 2 months ago #211876 by tpartner
Replied by tpartner on topic How to best start coding my own questions

...what do I need to make it accept only (natural) numbers? Also is there some way to restrict these numbers? Like from 1-5?

You could use <inputtype>integer</inputtype> but if values are limited to 1-5, I would use <inputtype>buttongroup</inputtype>.

Code:
<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>

 

Or would I need to define additional style elements in the css first?

You will need to develop CSS in conjunction with the HTML elements introduced via TWIG or JavaScript.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 2 months ago by tpartner.
The following user(s) said Thank You: Omti90
The topic has been locked.
  • Omti90
  • Omti90's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago #211936 by Omti90
Replied by Omti90 on topic How to best start coding my own questions
Thank you very much,the xls script works great. I've been trying to make it show my own text windows, but I'm a bit stumped how this works exactly. 

.card-sort-question .new-Text
{
    position: absolute;
    width: 20%;
    max-width: 340px;
    height: 120px;
    border: 2px solid rgb(19, 170, 64);
    background: #db1313;
}

I tried to create some custom text field in css with the script above and then show it using the following twig code.

{% 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>

I added the orange lines. This does sort of work since it prints the "labels" about where I would expect them.

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.
 
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #211952 by tpartner
Replied by tpartner on topic How to best start coding my own questions
You can explore the DOM and styles with your browser developer tools (F12) to see what is affecting various elements.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu, Omti90
The topic has been locked.
  • Omti90
  • Omti90's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago #211970 by Omti90
Replied by Omti90 on topic How to best start coding my own questions

tpartner wrote: You can explore the DOM and styles with your browser developer tools (F12) to see what is affecting various elements.
 

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).

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?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 2 months ago #211981 by tpartner
Replied by tpartner on topic How to best start coding my own questions
Completely clear the browser cache and refresh?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • ollehar
  • ollehar's Avatar
  • Offline
  • LimeSurvey GmbH Employee
  • LimeSurvey GmbH Employee
More
3 years 2 months ago #212040 by ollehar
Replied by ollehar on topic How to best start coding my own questions
Also feel free to discuss this on our Discord channel.
The topic has been locked.
  • Omti90
  • Omti90's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 month ago #212722 by Omti90
Replied by Omti90 on topic How to best start coding my own questions

tpartner wrote: Completely clear the browser cache and refresh?

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.

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).
[img

[img


As you can see the custom class isn't affected by the style I've defined in the cardsort.css.
cardsort.css

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?
cardsort.twig
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #212746 by tpartner
Replied by tpartner on topic How to best start coding my own questions
Can you activate a sample survey and give a link here so we can see the source ourselves?

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