Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Issues upgrading to version 3.28 from 2.50

  • AlexBell
  • AlexBell's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago #225409 by AlexBell
Please help us help you and fill where relevant:
Your LimeSurvey version: [Version 3.28.0+220215]
Own server or LimeSurvey hosting: Our Institution hosts the LimeSurvey(c) on its server
Survey theme/template: Fruity 
==================
We have just upgraded our LimeSurvey(c) from 2.50 to Version 3.28.0+220215 and my surveys structure and colour have been compromised. Please see attached .Iss file. I am specifically interested in changing the JavaScript for the side-by-side questions and for the question Array (Text) "Please share your education background starting from the most recent degree/qualification" where initially showing only one row and as the user fills the first row, the next one appears, etc. up to three rows. Please see the scripts below.

I have used Tony Partner's JavaScripts which now need editing, I think. I would be most grateful for any help as I do not know JavaScript (just using what has been created by the community so generously). Thank you.

JS for side-by-side questions:

<script type="text/javascript" charset="utf-8">        
    $(document).ready(function() {    
        // Identify the questions
        var thisQuestion = $('#question{QID}');
        var nextQuestion = $(thisQuestion).nextAll('div[id^="question"]:eq(0)');
        var theseQuestions = $(thisQuestion).add(nextQuestion);
        // Place the questions side-by side
        $(theseQuestions).wrapAll('<div style="width:100%; margin: 0 auto" />');
        theseQuestions.css({
            'float': 'left',
            'width': '50%'
        });
        $('> table', theseQuestions).css({
            'width': '100%'
        });
        // Some styling for the textareas
        $('textarea', theseQuestions).removeAttr('cols').css({
            'margin-left': '0',
            'margin-right': '0',
            'width': '100%'
        });
        // Equalize heights
        if($(thisQuestion).is(':hidden')) { 
            $(theseQuestions).css({
                'position': 'absolute',
                'left': '-9999em'
            }).show();
            equalizeHeights();
            $(theseQuestions).css({
                'position': 'relative',
                'left': 'auto'
            }).hide();
        }
        else {
            equalizeHeights();
        }
        function equalizeHeights() {
            var questionTextHeight = 0;
            $('td.questiontext', theseQuestions).each(function(i) {
                if($(this).height() > questionTextHeight) {
                    questionTextHeight = $(this).height()
                }
                $('td.questiontext', theseQuestions).height(questionTextHeight);
            });
            var answerHeight = 0;
            $('td.answer', theseQuestions).each(function(i) {
                if($(this).height() > answerHeight) {
                    answerHeight = $(this).height()
                }
                $('td.answer', theseQuestions).height(answerHeight);
            });
            var helpHeight = 0;
            $('td.survey-question-help', theseQuestions).each(function(i) {
                if($(this).height() > helpHeight) {
                    helpHeight = $(this).height()
                }
                $('td.survey-question-help', theseQuestions).height(helpHeight);
            });
        }
    });
</script>


JavaScript for Array (Text):

<script type="text/javascript">

    $(document).ready(function() {

        // A function to show subsequent rows of an array as options are checked
        function expandingArray(qID) {

            // Build an array of the question rows
            var arrayRow = '#question' + qID + ' table.question tbody tr';

            // Initially hide all rows unless an input was previously checked
            $( arrayRow ).each(function(i) {

                if ( $( arrayRow  + ':eq(' + i + ') input.radio:checked' ).length != 0 ) {
                    $(this).attr('name', 'clickedRow');
                }
                else {
                    $(this).attr('name', 'hidden').hide();
                }
            });

            // Now show the first hidden row
            addRow();

            // Add another row when an option is checked for the first time
            $( '#question' + qID + ' td.answer input.radio' ).click(function (event) {

                if ($(this).parents('tr:eq(0)').attr('name') != 'clickedRow') {
                    addRow();
                    $(this).parents('tr:eq(0)').attr('name', 'clickedRow');
                }

                // The original function of the click event
                checkconditions(this.value, this.name, this.type);
            });

            // Add another row when an table cell is clicked for the first time
            $( '#question' + qID + ' table.question tbody td' ).click(function (event) {

                if ($(this).parents('tr:eq(0)').attr('name') != 'clickedRow') {
                    addRow();
                    $(this).parents('tr:eq(0)').attr('name', 'clickedRow');
                }
            });

            // Function to add a row
            function addRow() {
                $( arrayRow + '[name="hidden"]:first' ).attr('name', 'visible').show();
                // Now, scroll down
            }
        }

        // Call the function with a question ID
        expandingArray(37536);

    });
</script>

Thank you.
Alex

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 7 months ago #225410 by Joffm
Replied by Joffm on topic Issues upgrading to version 3.28 from 2.50
1. side by side
Read this
[url] forums.limesurvey.org/forum/design-issue...s-same-height#216299 [/url]
Don't forget to replace this line
var thisQuestion = $('#question34824');
with
var thisQuestion = $('#question{QID}');

2. array
You may use subquestion relevance; all ells of the previous row have to be filled.
E.g. education
2nd row: !is_empty(self.sq_SQ001_SQ005) and !is_empty(self.sq_SQ001_SQ001) and !is_empty(....
3rd row: !is_empty(self.sq_SQ002_SQ005) and !is_empty(self.sq_SQ002_SQ001) and !is_empty(....

But you may have a look at this option to dynamically add new rows.
Only the second script here
[url] forums.limesurvey.org/forum/can-i-do-thi...ay-javascript#214902 [/url]

But the first (dropdowns in array cells) may be of intereest, too.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: AlexBell

Please Log in to join the conversation.

  • AlexBell
  • AlexBell's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago - 2 years 7 months ago #225439 by AlexBell
Replied by AlexBell on topic Issues upgrading to version 3.28 from 2.50
Dear Joffm,

I hope you are  well. Thank you for your quick response and guidance. Your solutions work like a charm! Much appreciated.
I have fixed most of the issues (thank you also pointing to the first dropdown) but have the following ones plus another request if possible (please find my .Iss attached):

1. I keep receiving the following error: An error occurred saving a response to survey id Course Registration 2022 - 715486DATA TO BE ENTERED:(followed by all the responses completed correctly and at the end showing)SQL CODE THAT FAILED:Error on response update
2. The alignment of the questions (two ore more in one row) only seem to work in a vanilla template - I would prefer Bootswatch but once selected, the alignment breaks - questions margins overlap. Is it possible to fix please?

3. Ideally, I would want to put countries dropdown and add a datepicker in the Array (Text) questions - E.g.: in "Please share your education background starting from the most recent degree/qualification."  in columns 5 and 6 respectively. I would be most grateful for any help please.

4.  Optional as I am asking for too much now: Is it possible to help me put proper validation for the email address to allow only exact copy of the original in the validation (second row) - these are the last two columns of the questions "Please share your correspondence address and your contact details."

Thank you so much for your kind help and support.
Regards.
Alex
Last edit: 2 years 7 months ago by AlexBell.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 7 months ago #225452 by Joffm
Replied by Joffm on topic Issues upgrading to version 3.28 from 2.50
Hi, 
I wonder why you try to put questions side by side insted of using an array like this
Array with dropdowns and datepicker.




And in your other arrays, include them as well.

And validation of email.
Enter inb the "question validation equation" of the second: self.sq_SQ007==self.sq_SQ008
Same for phone number.

Here a small sample survey with the first two questions
 

File Attachment:

File Name: limesurvey...6322.lss
File Size:33 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: AlexBell

Please Log in to join the conversation.

  • AlexBell
  • AlexBell's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago #225461 by AlexBell
Replied by AlexBell on topic Issues upgrading to version 3.28 from 2.50
Dear Joffm,
As always, thank you for your quick and kind help and support.

Never thought of putting the dropdown and datepicker in an array - thank you for the idea and for the Jscript - I am most grateful!

Thank you also for the validation solution.

Warm regards
Alex

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose