json-editor / json-editor

JSON Schema Based Editor
MIT License
4.43k stars 654 forks source link

Editing array of string doesn't work anymore #514

Closed Cheprod closed 5 years ago

Cheprod commented 5 years ago

General information

Expected behavior

Normal behaviour with add/remove button to add/remove string value in the array. Work well in version 1.3.5

Actual behavior

Just a blank field CC

Steps to reproduce the behavior

Direct link to example: https://json-editor.github.io/json-editor/?schema=N4IgLglmA2CmIC4QDMJwCIEMyYEqwGMB7AJwBNYSQAaECgZwJIgAdIiA7REAYU9QDmAVxLYInAAQBlAgAtYAW0wTkpCQDE0sLDnzFylGuACeLeEiIAjAFaEwRliSJmSkWPUSgh9WAFUAKjyedO5MrOxcSACSHGQQAI5CsBL0EBKSQpDQED4S0ADk8iLJATwSLEQiecmQCu44CixGYKbmIJZERHCYXLQUyJhC0PYIYCRJAL603n6BmnAAcph1wQxhbOKRIDFxicmp6RwSmWg5yQVFJCWB5ZUk1RIcRAoKAJcPqHIQhrQtZtwdLqwHpGfqDYaIMaTX4QOr0BosdSkJQjUBrZgbTjcJEkFESMhCCS1erLFgSAAUsAAHhIEBIAKRkAD09IULIAmgyABIIekAWV5UgAlAA6CQAGUwOXo7wAbhAKLcqidsj57nAVMjsOVMPcyK8BpkKTi8VEpAB5AAcADYAAwARlFzVa3HhzA4AlBsENEKQ9PZICm4EwAnoSxWCDRoQxEW44pyYGSDEez3o+JqIbTAAOJK8wld8T00xrPrJvnqk5wOK93GKpGlBgQhEccKHHvl6ikWHmIKhXtQJGg02rOGAiZU03nmGA02Qix8IF9KCLnf8kLrRMZmlA4Nx/JmJP4IEZVLjsNwcJZd7RnBEPJG6DlMFfYAB9YjQaCYFg+SHjWC0BumDGO+o5ONA9CvmAzh/tCIBQIo96gH8bRuhAHrbjAbT7qGga0Ao6FRImCj3ra0wcAkSREYhsGwEGADWsCwIiWj0OgIjoQIMRSIQqzRuEmzcAszyWAWio+MQsTuOUsCxD0Y5wPQewQRIklqrKlDVGmpblrOlYcNWtYSlK9BqhIOa2jJuKwGOiocMkLCYMOQgsI4sKaYpKiLmWlD0Cuvwukg6GJgIPwgARFEKEICiILaQbEC8UBSHcBCwOG5hRowMaCUgwkKKpzwsHAtmEgoRAEhqZD5EQACf5ROPKskKckCUEfYAVriAaEYRMQZXIkEBXGQiAANogDMpRGBNcxaOlzSZnNtCMcx8zuOx7pcRwPEEEYrVJSlaXLPAAC6tCnii3AENgsACKQ3weLQlhOYuPDXbdJDGEeWHcAACu6BCsJg0CBkAA==&value=N4IgrgzgpgqgKgYRALgC4CcxQDTmvBAMQEsAbKAOQEMBbKFDLXVKgcwmrpQG0BdXANZQoABxLkIAETDpiAO1YBJOQGUoAYxQAGXOoD2NGsVQq9M9ZVr1kIEAF8gA&lib_switcher=&prompt_before_delete&upload=function(a,b,c){console.log(%22Upload%20handler%20required%20for%20upload%20editor%22)}&theme=foundation5&iconlib=fontawesome4&object_layout=normal&show_errors=interaction

Cheprod commented 5 years ago

To confirm the same test from the original schema of the page modify to have pets as string :

https://json-editor.github.io/json-editor/?schema=N4IgLglmA2CmIC4QAVYCcDOB7AdiANOAJ4AO8SWARgFawDGYBIasAjgK4QsAmiA2iBwBDALbxCQgObiQ3IWBkAzIQDcsaKLAD6dLNHVNpObuib668iLiZkwGEAF1CJNFjJpIsewlDCxiUDBSchAMMA0cSSYTDDoNEkhrJAAxLjCAAiFjdIAZIQy/GREIHBzYSLAAC0QAFkITZXZoRiQAKXRYESJ0gBF1PABfCWkA4jJEEBKFaTRo2EbmxAAmAFZCYpwIEXYRRABGAA51oQAPLZ3EAE5LoZBlNQ0FHT0DHzGQsIiowkV1EXkJrp9LNCJAYCF7upNOkgQZ6vMhE0WiAAMSKZQrAAMmJAtyMJlmbyC4yQnxK3xA5QuCAE/zgTEUnSE9IctzkClGxI+4XJDL+AKQ7JkbkSOG8oEU0HkJAgdAA1oTgANlYRzJYkoFghMqLQGEwwfSkDksBZRTZXO5POKQHQoEROVrSTzInMFsiAMpZdLJNBZW2xLC4whheTkTUk0LOikNRGLJAAYQAgkGbXaQxyiY7I185rF4makAAVSoQDDpUvpIzoUPcTLsMBYf6QCzQaDdRSuETpKqwdIuWAqKzsMtgADuWHSiggsGg3HsoM6JClGZAwGAtqCKvSa/TsGVTFH8jo1TeG/tSDVooAdGemLuJperDgr/flSqQLZrVyJkI0L77T8/LImAQiUPSoJQIaKCwHYTDsJsHCwAAkgoIjeOE7CwIQmhoQ6EZki6EHghMqCMGyCJIvwIB8Dq9BgOkADyNB0Q4jhvkAA=&value=N4IgdghgtgpiBcIBSMBOMoE8AEARA9qmCADQgQDmc8ATAKxkBmEAboQJYAuMA+gMb4ANoQQgAxI2Z0ADNNIgqYACZpRUCILhklEbqPnC+u9vmLxgAXzIAHGJwDOCANoBdC0A&lib_switcher=&prompt_before_delete&upload=function(a,b,c){console.log(%22Upload%20handler%20required%20for%20upload%20editor%22)}&theme=bootstrap2&iconlib=fontawesome4&object_layout=normal&show_errors=interaction

Print screen : CC

pmk65 commented 5 years ago

Seems to have something to do with uniqueItems. If you set uniqueItems": false, the table controls will show up.

Cheprod commented 5 years ago

Yes, I did't notice this detail ;)

It looks like that nothing is done if uniqueItems is set to true in this section of code :

// Specialized editors for arrays of strings
JSONEditor.defaults.resolvers.unshift(function(schema) {
  if(schema.type === "array" && schema.items && !(Array.isArray(schema.items)) && schema.uniqueItems && ['string','number','integer'].indexOf(schema.items.type) >= 0) {
    // if 'selectize' enabled it is expected to be selectized control
    if (JSONEditor.plugins.selectize.enable) {
      return 'arraySelectize';
    }
    // otherwise it is select
    else {
      return 'multiselect';
    }
  }
});
pmk65 commented 5 years ago

I think it's the correct behavior in 1.4.0-beta.0 It makes sense that uniqueItems has to be false when using array/table editor as source. As you can't ensure that the user doesn't add a duplicate value.

Cheprod commented 5 years ago

This feature works well in the 1.3.5 with array of string :

CC

pmk65 commented 5 years ago

@Cheprod I think I got it figured out, and will submit a PR with fix in the develop/2.x branch (That's the only branch I'll submit PRs to.) In the develop/2.x branch the Select2 plugin have been moved to separate editor, so there's an additional check. But basically the fix just removes the return 'multiselect'. Then it works with both uniqueItems true or false.

pmk65 commented 5 years ago

Fix have been added to the develop/2.x branch.