bootstrap-duallistbox icon indicating copy to clipboard operation
bootstrap-duallistbox copied to clipboard

POST variable naming error

Open LLFT opened this issue 4 years ago • 1 comments

Hello, On the following code:


<select name="Gauche[]" class="duallistbox" id="inputSelectGroup" multiple="multiple" size="20" >

<optgroup label="Grp1">
<option selected="selected" value="1">option 1</option>
<option selected="selected" value="2">option 2</option>
</optgroup>
<optgroup label="Grp2">
<option selected="selected" value="3">option 3</option>
<option selected="selected" value="4">option 4</option>
</optgroup></select>

<script src="./plugins/bootstrap4-duallistbox/jquery.bootstrap-duallistbox.js"></script>
<script>
    $(function () {
        $('.duallistbox').bootstrapDualListbox({
            preserveSelectionOnMove: 'moved',
            moveOnSelect: false,
        });
    });
</script>


After deselecting option 1 and validating the form we get the table:

Debug Chrome : 
	Gauche[]_helper2: 1
	Gauche[]: 2
	Gauche[]: 3
	Gauche[]: 4

PHP $_POST 
[Gauche] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
            [3] => 4
        )

The variable is therefore false.

Correcting the code at setHelperSelectNamePostfix like this:

setHelperSelectNamePostfix: function(value, refresh) {
      this.settings.helperSelectNamePostfix = value;
      if (value) {
        this.elements.select1.attr('name', this.originalSelectName.replace('[]','') + value + '1[]');
        this.elements.select2.attr('name', this.originalSelectName.replace('[]','') + value + '2[]');
      } else {
        this.elements.select1.removeAttr('name');
        this.elements.select2.removeAttr('name');
      }
      if (refresh) {
        refreshSelects(this);
      }
      return this.element;
    },

We get the table:

Debug Chrome : 
	Gauche_helper1[]: 1
	Gauche[]: 2
	Gauche[]: 3
	Gauche[]: 4

PHP $_POST :

    [Gauche_helper2] => Array
        (
            [0] => 1
        )

    [Gauche] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 4
        )

LLFT avatar Jun 19 '20 07:06 LLFT

I think I fixed the problem with using this plugin with PHP. I modified the following lines, Around line 43 helperSelectNamePostfix: 'helper_', // Original Line Below // helperSelectNamePostfix: '_helper', // 'string_of_postfix' / false

Around Line 653 this.elements.select1.attr('name', value + '1_' + this.originalSelectName); this.elements.select2.attr('name', value + '2_' + this.originalSelectName); // Below are original Lines
// this.elements.select1.attr('name', this.originalSelectName + value + '1'); // this.elements.select2.attr('name', this.originalSelectName + value + '2');

joegrcs avatar Oct 29 '21 17:10 joegrcs