Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select2 doesn't refer enumSource of item in array. #1544

Open
victorlut opened this issue Apr 12, 2024 · 12 comments
Open

select2 doesn't refer enumSource of item in array. #1544

victorlut opened this issue Apr 12, 2024 · 12 comments
Assignees

Comments

@victorlut
Copy link

General information

select2 doesn't refer enumSource of item in array.

  • json-editor version: latest

Expected behavior

"persons" should look like a tag element inside the elements of enumSource.

Actual behavior

select2 doesn't refer enumSource of array item. If I refer to enum, it works well. Or if I change the type into string, it works well too. I think, select2 array doesn't refer to enumSource, but enum.

Steps to reproduce the behavior

Direct link to example: https://json-editor.github.io/json-editor/

"persons": {
  "type": "array",
  "format": "select2"
  "uniqueItems": true,
  "items": {
    "type": "string",
    "watch": {
      "personas": "document.personas"
    },
    "enumSource": [
      {
        "source": "personas",
        "title": "{{item.__text}}",
        "value": "{{item.__text}}"
      }
    ]
  }
}
@germanbisurgi
Copy link
Collaborator

Hi @victorlut. I need the complete schema to reproduce this. Specifically the part related too document.personas

@victorlut
Copy link
Author

victorlut commented Apr 21, 2024

@germanbisurgi Thanks for your reply. I can't share it fully but here's Personas. Personas is correctly located inside document, and it works well unless I use select2.

"personas": {
          "type": "array",
          "title": "Personas",
          "format": "table",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "title": "Persona",
            "format": "table",
            "properties": {
              "image": {
                "type": "string",
                "format": "uri",
                "qt-uri-protocols": ["https"],
                "qt-uri-extensions": [".svg"],
                "title": "Image",
                "description": "Type Uri here",
                "links": [
                  {
                    "href": "{{self}}",
                    "mediaType": "image"
                  }
                ]
              },
              "text": {
                "type": "string",
                "title": "Text"
              }
            },
            "required": ["text", "image"]
          }
}

@germanbisurgi
Copy link
Collaborator

Could you provide a similar schema that produces the same error so i can debug this? At first glance i would say that the problem lays the JSON path:

"watch": {
  "personas": "document.personas"
}

It could be necessary to change it depending on the structure of your schema

@victorlut
Copy link
Author

Could you provide a similar schema that produces the same error so i can debug this? At first glance i would say that the problem lays the JSON path:

"watch": {
  "personas": "document.personas"
}

It could be necessary to change it depending on the structure of your schema

Sure. If you change select2 to table, you can see it's working. But only select2 format doesn't work.

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "$ref": "#/definitions/Document",
  "definitions": {
    "Document": {
      "type": "object",
      "id": "document",
      "additionalProperties": false,
      "properties": {
        "personas": {
          "type": "array",
          "title": "Personas",
          "format": "table",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "title": "Persona",
            "format": "table",
            "properties": {
              "image": {
                "type": "string",
                "format": "uri",
                "qt-uri-protocols": ["https"],
                "qt-uri-extensions": [".svg"],
                "title": "Image",
                "description": "Type Uri here",
                "links": [
                  {
                    "href": "{{self}}",
                    "mediaType": "image"
                  }
                ]
              },
              "text": {
                "type": "string",
                "title": "Text"
              }
            },
            "required": ["text", "image"]
          }
        },
        "journeys": {
          "type": "array",
          "title": "Journeys",
          "items": {
            "type": "object",
            "title": "Journey",
            "properties": {
              "persons": {
                "type": "array",
                "format": "select2",
                "uniqueItems": true,
                "description": "You can choose some of Personas list described above",
                "items": {
                  "type": "string",
                  "name": "person",
                  "title": "person",
                  "watch": {
                    "personas": "document.personas"
                  },
                  "enumSource": [
                    {
                      "source": "personas",
                      "title": "{{item.text}}",
                      "value": "{{item.text}}"
                    }
                  ]
                }
              }
            }
          }
        }
      },
      "title": "Document"
    }
  }
}

@germanbisurgi
Copy link
Collaborator

Move "format": "select2" from persons to persons.items schema

@victorlut
Copy link
Author

Move "format": "select2" from persons to persons.items schema

It's not working. Does it work on your side?

@germanbisurgi
Copy link
Collaborator

yes -> example

@victorlut
Copy link
Author

victorlut commented Apr 30, 2024

yes -> example

Sorry. It's not what it should show. The result will be the same even if you remove format property. select2 should look like tags. Like this one. update

@schmunk42
Copy link
Collaborator

@victorlut It should look like this, right?

image

But the select2 does not read the "personas" from the first array.

@victorlut
Copy link
Author

@victorlut It should look like this, right?

image

But the select2 does not read the "personas" from the first array.

Yes, exactly!

@simontaurus
Copy link

I guess this duplicates #665 and #1484 ?

@victorlut
Copy link
Author

Did anyone found the solution yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants