How to best start coding my own questions

More
8 months 1 week 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.

Please Log in to join the conversation.

More
8 months 1 week ago #211819 by tpartner
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

Please Log in to join the conversation.

More
8 months 1 week ago #211822 by tpartner

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

Please Log in to join the conversation.

More
8 months 1 week ago - 8 months 1 week ago #211859 by Omti90

...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: 8 months 1 week ago by Omti90.

Please Log in to join the conversation.

More
8 months 6 days ago - 8 months 6 days ago #211876 by tpartner

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

<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.
Attachments:
Last edit: 8 months 6 days ago by tpartner.
The following user(s) said Thank You: Omti90

Please Log in to join the conversation.

More
8 months 5 days ago #211936 by Omti90
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.
 

Please Log in to join the conversation.

More
8 months 5 days ago #211952 by tpartner
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

Please Log in to join the conversation.

More
8 months 5 days ago #211970 by Omti90

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?

Please Log in to join the conversation.

More
8 months 5 days ago #211981 by tpartner
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.

Please Log in to join the conversation.

More
8 months 2 days ago #212040 by ollehar
Also feel free to discuss this on our Discord channel.

Please Log in to join the conversation.

More
7 months 2 weeks ago #212722 by Omti90

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).
File Attachment:

File Attachment:


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

Please Log in to join the conversation.

More
7 months 2 weeks ago #212746 by tpartner
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.

Please Log in to join the conversation.

More
7 months 3 days ago #213354 by Santoke5
Yeah, that's a very good question. It will be much helpful if the OP shares the link here. So that all of them members can visit and leave helpful replies. 

Please Log in to join the conversation.

More
5 months 4 weeks ago #215084 by Omti90
Sorry that turned out rather more difficult than I thought it might be. Is there some how to guide I missed?
Anyway, now that I've got some time to have a look at this again. I'm rather glad I started early... I've uploaded what I've done so far if someone wants to have a look: mega.nz/file/VpBXBapK#9c5Lphxa43pSl1y2oz...AHTga0pzL_rTRJKhnLW0

That said, I'm not sure if the .css file is affecting what's being shown at all. Since even changing stuff in working styles doesn't seem to affect what's shown in limesurvey. If I change the coloration of the answers, there's no effect.

If I literally delete the entire file and save, there's no effect. I'm honestly baffled why that is. I deleted the entire cache of my secondary browser thrice, trying this in different configurations without any effect.

It's almost like it's saved the cardsort.css once in my databank and is using that backup, rather than getting it from the upload folder. Could that have happened? Do I need to force reupload this somehow?

Please Log in to join the conversation.

More
5 months 4 weeks ago #215133 by tpartner
I asked for a link to a live survey so I could see the source.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now