vitalets / x-editable

In-place editing with Twitter Bootstrap, jQuery UI or pure jQuery
http://vitalets.github.io/x-editable
MIT License
6.51k stars 1.73k forks source link

x-editable Select2 values not submitting #1093

Closed anupalhub closed 6 years ago

anupalhub commented 6 years ago

Here is my code implementation:

<a href="javascript:;" class="editableCustomSelectField" data-type="select2" 
data-pk="2270" data-multiple="true" 
data-source="http://localhost/Fields/getDropdown/3" 
data-value="" data-name="3" data-title="Colleges" ></a>

and here is the jQuery

       $('.editableCustomSelectField').each(function(){
                $(this).editable({
                    showbuttons: true,
                    inputclass : 'form-control input-sm',
                    url: baseUrl+'/Fields/editLead/'+lead_id,
                    ajaxOptions: {
                        dataType: 'json'
                    },
                    send: 'always',
                    validate: function(value) {
                        if($(this).data('required') && $.trim(value) == '') {
                            return 'This field is required';
                        }
                    },
                    success: function(json, newValue) {
                        if(json.success)
                            $.bootstrapGrowl('<i class="fa fa-check"></i> Updated successfully');
                        else
                            return json.error;
                    },
                    select2: {
                        cacheDataSource: true,
                        multiple: $(this).data('multiple'),
                        allowClear: true,
                        placeholder: 'Choose...',
                        id: function (item) {
                            return item.id;
                        },
                    },
                    tpl: '<select></select>',

                });
            });

Json source is

[{"id":4,"text":"Uni one","value":4},{"id":5,"text":"Uni two","value":5},{"id":6,"text":"Uni three","value":6},{"id":7,"text":"Uni four","value":7}]

Everything working fine. but when i submit the after selecting it just return this without the values selected both in multiple true or false!

array(
    'name' => '3',
    'pk' => '2270'
)

Please suggest any solution. Thanks in advance

anupalhub commented 6 years ago

Solved. I was using old version of select2.