question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 !

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

4reactions
clickfwdcommented, Jun 19, 2016

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; }

0reactions
c-holbechcommented, Oct 13, 2017

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

json-editor - Bountysource
When updating JSON schema with new optional properties and then loading a JSON which does not have that optional properties, they are not...
Read more >
@json-editor/json-editor | Yarn - Package Manager
js). Fixed problem with JSON and collapse buttons setting display: none; on button and not container. (src/object.js) So now compact in combination with...
Read more >
Source - GitHub
Fix of #470 - Constant enumSource value specified as array of strings causes a ... Fixed problem with JSON and collapse buttons setting...
Read more >
Select2 json data not working - Stack Overflow
This line gives an error: var jsonValue = JSON.parse($(this).attr('data-json')).val());.
Read more >
drupal-swagger-ui-formatter-support-swagger-ui-3.0-2958783 ...
If +identifiable sections of that work are not derived from the Program, ... [tag v.2.1.4](https://github.com/swagger-api/swagger-ui/tree/v2.1.1) | -2.0.24 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found