json-editor icon indicating copy to clipboard operation
json-editor copied to clipboard

Select2 issues : v4 not working with jsoneditor, and enumSource not working with uniqueItems array

Open thewebkit opened this issue 9 years ago • 6 comments

Hi there,

First of all, thanks a lot for your work, jsoneditor is amazing !

I'll drop here some issues I've found with select2, and that matches other previous issues i've found on github. This post is just for issue report purposes, in case anyone else is looking for an answer, and eventually to merge all the select2 issues. Feel free to close or merge this post if needed.

1) Select2 v4 not working properly with jsoneditor

I was at first using select2 v4.0.2 and jsoneditor wasn't getting any value. Searching the repo for similar issues, i've found this post that refer to it : issues/231

Temporary fix : use previous version of select2. For me, v3.5.4 worked well.

2) "array" type with uniqueItems not working with enumSource

I've also found a related issue here on the repo, althought it's a closed issue : issue/225

Here is my code, just in case. "products" is a another array type with object items. I'm using mustache template.

"choice_excluded": {
       "type": "array",
       "uniqueItems":true,
       "format":"select",
       "items": {
              "type":"string",
              "watch": {  "excluded_products": "products"  },
              "enumSource": [{
                      "source": "excluded_products",
                      "title": "{{item.name_product}}",
                      "value": "{{item.slug_product}}"
              }]
       }
}

Am I doing something wrong ?

I haven't found a satisfying solution for now, so i'm just using an empty array, and I need to add each item manually.

Thanks in advance !

thewebkit avatar May 20 '16 14:05 thewebkit

I am also having issues with select2 v4 when using the "startval" option or the "setValue" method. I disabled it by overriding the prototype method "setupSelect2" by adding this line before initializing the editor:

JSONEditor.defaults.editors.select.prototype.setupSelect2 = function() { this.select2 = null; }

clickfwd avatar Jun 19 '16 21:06 clickfwd

This worked for me, select2 would break quite a few things otherwise.

samvaughton avatar Jul 06 '16 14:07 samvaughton

I also have issues with select2 (v4.0.3):

  1. enum option is not selected correctly for an array item
  2. select2 remains disabled if I open and close the properties window

step307 avatar Aug 12 '16 13:08 step307

@samvaughton Thanks, this makes the starval and setValue work on a single value select, but on a multi-select (i.e. an array), only one value is selected.

Any news on select2 support?

Andargor avatar Oct 19 '16 04:10 Andargor

Any news on uniqueItems not working with enumSource? I'd like to have a multiple selectbox with key/value options and I have no idea how to implement it. well except for using checkboxes for each entry :/

bschelling avatar Jan 14 '17 20:01 bschelling

select2 v4 does not update values because the listner for multiselect only listen to 'select2-blur' event. This event has not been implemented (yet) in v4. in select editor someone have added support for 'change' event, but this has not been added in the multiselect editor.

Under setupSelect2 for JSONEditor.defaults.editors.multiselect I added:

this.select2.on('change',function() {
  var val =self.select2.select2('val');
  self.value = val;
  self.onChange(true);
});

below the existing section for 'select2-blur'.

Now value is updated on changes in select2 multiselect.

HTH (very new to github, so don't know how to submit this)

c-holbech avatar Oct 13 '17 09:10 c-holbech