Welcome to the LimeSurvey Community Forum

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

Ajouter des colonnes de tableau en fonction du besoin

  • Jibemas
  • Jibemas's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 weeks 18 hours ago #267646 by Jibemas
Bonjour,

Je cherche à créer un tableau "dynamique"  qui permettrait aux personnes qui complètent le questionnaire, de pouvoir d'ajouter des colonnes en fonction de leur besoin.

Actuellement, j'ai créé différentes colonnes (jusqu'à 6 voir PJ. Exemple), alors que certaines personnes répondant au questionnaire n'auront pas besoin d'autant de colonnes.

Mon idée est de créer un tableau de 1 à 2 colonnes avec une "option", un "bouton" permettant d'ajouter des colonnes en fonction du besoin. (Voir PJ. Exemple2)

Merci pour votre aide,

Cordialement,

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
2 weeks 18 hours ago #267647 by DenisChenu
Il faut le faire en javascript : www.limesurvey.org/manual/Workarounds:_M...arLengthArray_script

Sauf si tu as besoin d'un nombre infini de lignes, dans ce cas gitlab.com/SondagesPro/QuestionSettingsT...ionSpreadsheetSurvey

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • Jibemas
  • Jibemas's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 weeks 15 hours ago #267654 by Jibemas
Merci pour la réponse,

Cependant, je ne suis pas un très bon développeur, dois-je remplacer la variable "qID" par mon numéro de sous-question ?

Cordialement,

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
1 week 6 days ago #267680 by DenisChenu
Le tutoriel est pour le cas pou tu ajoute le script dans le texte de la quetsion.

Enlève les lignes <script type="text/javascript"> et </script>

Pose le script dans le bloc script et test sur une question de type tableau de texte.

Par contre : c'ets dans le sens inverse : on ajote des lignes, pas des colonnnes.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • Jibemas
  • Jibemas's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 5 days ago #267692 by Jibemas
Merci encore pour le temps que vous consacrez à ma problématique.

Cependant, lors que j'ajoute le code dans l'onglet script de ma question Tableau de texte.

Les 2 boutons apparaissent mais rien ne se produit (PJ. ExempleBouton+-). De plus, lors de la visualisation du questionnaire, les boutons apparaissent en bas du questionnaire et non au niveau de la question (PJ. ExempleVisuQuestionnaire).

Vous trouverez également le seul avertissement commun que j'ai sur la fonction "AddRow" et "RemoveRow"

Cordialement,

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 week 5 days ago #267693 by Joffm
Bonjour

Par contre : c'ets dans le sens inverse : on ajote des lignes, pas des colonnnes.

Il faut donc faire pivoter la tableau.
 
Mais il semble que vous faites encore des erreurs.
Envoyez donc l'export lss de cette partie de l'enquête

Joffm

 

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

Please Log in to join the conversation.

  • Jibemas
  • Jibemas's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 5 days ago - 1 week 5 days ago #267694 by Jibemas
Bonjour,

Je suppose que c'est ce que vous vouliez, malgré que le format soit différent ?

Cordialement,
Last edit: 1 week 5 days ago by Jibemas.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 week 5 days ago #267695 by Joffm
@DenisChenu l'a dit : Vous ne pouvez ajouter que des lignes, pas des colonnes.

Et s'il vous plaît, n'exporte qu'au format lss, pas lsq, pas lsg.

Joffm

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

Please Log in to join the conversation.

  • Jibemas
  • Jibemas's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 5 days ago #267698 by Jibemas
Voici le .lss

Cordialement,

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 week 5 days ago #267702 by Joffm
Bonjour

Votre script semble exécuter la version 6.x. être incompatible; c'est pour une ancienne version.
Veuillez comparer !
vieux:
Code:
  // Function to add a row, also shows the Remove element and hides the
      //Add element if all rows are shown
      function addRow(qID) {
        var arrayRow = '#question' + qID + ' ul.ls-answers li.answer-item';
        var rowCount = $( arrayRow ).size() - 1;
        $( arrayRow + '[name="hidden"]:first' ).attr('name', 'visible').show();
        $( 'div#removeButton'+qID ).show();
        if ( $( arrayRow + ':eq(' + rowCount + ')' ).attr('name') == 'visible' )  {
          $( 'div#addButton'+qID ).hide();
        }
      }
 
      // Function to remove a row, also clears the contents of the removed row,
      // shows the Add element if the last row is hidden and hides the Remove
      // element if only the first row is shown
      function removeRow(qID) {
        var arrayRow = '#question' + qID + ' ul.ls-answers li.answer-item';
        var rowCount = $( arrayRow ).size() - 1;
        $( arrayRow + '[name="visible"]:last input[type="text"]' ).val('');
        $( arrayRow + '[name="visible"]:last' ).attr('name', 'hidden').hide();
        $( 'div#addButton'+qID ).show();
        if ( $( arrayRow + ':eq(1)' ).attr('name') == 'hidden' )  {
          $( 'div#removeButton'+qID ).hide();
        }
      }
 
      // Just some initialization stuff
      var arrayRow = '#question' + qID + ' ul.ls-answers li.answer-item';
      var rowCount = '';


nouveaux:
Code:
          // Function to add a row, also shows the Remove element and hides the
            //Add element if all rows are shown
            function addRow(qID) {
                var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
                var rowCount = $( arrayRow ).size() - 1;
                $( arrayRow + '[name="hidden"]:first' ).attr('name', 'visible').show();
                $( 'div#removeButton'+qID ).show();
                if ( $( arrayRow + ':eq(' + rowCount + ')' ).attr('name') == 'visible' )  {
                    $( 'div#addButton'+qID ).hide();
                }
            }
 
            // Function to remove a row, also clears the contents of the removed row,
            // shows the Add element if the last row is hidden and hides the Remove
            // element if only the first row is shown
            function removeRow(qID) {
                var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
                var rowCount = $( arrayRow ).size() - 1;
                $( arrayRow + '[name="visible"]:last input[type="text"]' ).val('');
                $( arrayRow + '[name="visible"]:last' ).attr('name', 'hidden').hide();
                $( 'div#addButton'+qID ).show();
                if ( $( arrayRow + ':eq(1)' ).attr('name') == 'hidden' )  {
                    $( 'div#removeButton'+qID ).hide();
                }
            }
 
            // Just some initialization stuff
            var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
            var rowCount = '';
 


Voici le script
Code:
$(document).ready(function() {
 
   // A function to add or remove rows of an Array (Multi Flexible)(Text) question
    function varLengthArray(qID) {
        
        if ($('#question'+qID+'').length > 0) {
            
            // The HTML content of the Add/Remove elements - modify as you wish
            var addContent = '[+] Zeile zufügen';
            var removeContent = '[-] Zeile löschen';
 
            // Create the Add and Remove elements &amp; insert them
            var el1 = document.createElement('div');
            el1.setAttribute('id','addButton'+qID);
            el1.setAttribute('class','btn btn-success');
            document.body.appendChild(el1);
            var el2 = document.createElement('div');
            el2.setAttribute('id','removeButton'+qID);
            el2.setAttribute('class','btn btn-danger');
            document.body.appendChild(el2);
 
            // Move them to after the array
            $( 'div#addButton'+qID ).appendTo($( '#question' + qID + ' table.ls-answers' ).parent());
            $( 'div#removeButton'+qID ).appendTo($( '#question' + qID + ' table.ls-answers' ).parent());
 
            // Insert their HTML
            $( 'div#addButton'+qID ).html( addContent );
            $( 'div#removeButton'+qID ).html( removeContent );
 
            // Style the elements - you can modify here if you wish
            $( 'div#addButton'+qID ).css({
                'margin':'10px 0 10px 10px',
                'padding':'1px',
                'text-align':'center',
                'width':'auto',
                'cursor':'pointer',
                'float':'left'
            });
 
            $( 'div#removeButton'+qID ).css({
                'margin':'10px 0 10px 10px',
                'padding':'1px',
                'text-align':'center',
                'width':'auto',
                'cursor':'pointer',
                'float':'left'
            });
 
            // Initially hide the Remove element
            $( 'div#removeButton'+qID ).hide();
 
            // Call the functions below when clicked
            $( 'div#addButton'+qID ).click(function (event) {
                addRow(qID);
            });
            $( 'div#removeButton'+qID ).click(function (event) {
                removeRow(qID);
            });
 
            // Function to add a row, also shows the Remove element and hides the
            //Add element if all rows are shown
            function addRow(qID) {
                var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
                var rowCount = $( arrayRow ).size() - 1;
                $( arrayRow + '[name="hidden"]:first' ).attr('name', 'visible').show();
                $( 'div#removeButton'+qID ).show();
                if ( $( arrayRow + ':eq(' + rowCount + ')' ).attr('name') == 'visible' )  {
                    $( 'div#addButton'+qID ).hide();
                }
            }
 
            // Function to remove a row, also clears the contents of the removed row,
            // shows the Add element if the last row is hidden and hides the Remove
            // element if only the first row is shown
            function removeRow(qID) {
                var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
                var rowCount = $( arrayRow ).size() - 1;
                $( arrayRow + '[name="visible"]:last input[type="text"]' ).val('');
                $( arrayRow + '[name="visible"]:last' ).attr('name', 'hidden').hide();
                $( 'div#addButton'+qID ).show();
                if ( $( arrayRow + ':eq(1)' ).attr('name') == 'hidden' )  {
                    $( 'div#removeButton'+qID ).hide();
                }
            }
 
            // Just some initialization stuff
            var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
            var rowCount = '';
 
            // Initially hide all except first row or any rows with populated inputs
            $( arrayRow ).each(function(i) {
                if ( i > 0 ) {
                    // We also need to give the hidden rows a name cause IE doesn't
                    // recognize jQuery :visible selector consistently
                    $( this ).attr('name', 'hidden').hide();
 
                    $('input[type=text]', this).each(function(i) {
                        if ($(this).attr('value') != '') {
                            $(this).parents('tbody:eq(0)').attr('name', 'visible').show();
                            $( 'div#removeButton'+qID ).show();
                        }
                    });
                    rowCount = i;
                }
            });
        }
    }
 
    // Call the function with a question ID
    varLengthArray({QID});
 
});
En plus, tu avais oublié ça
$(document).ready(function() {
...
});


 

Joffm

 

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

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
1 week 5 days ago #267705 by DenisChenu

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 week 5 days ago - 1 week 5 days ago #267706 by Joffm
Autre possibilité :
 
Deux questions "textes multiples"
Et ici, l'autre script est correct.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 week 5 days ago by Joffm.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

Moderators: Nickkoholchtpartner

Lime-years ahead

Online-surveys for every purse and purpose