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

Is it possible to create "template" field in array of elements?

Open nardev opened this issue 7 years ago • 2 comments

I have some schema like this:

  schema: {
  title: "TOPICS AND RULES",
  disable_edit_json: true,
  disable_properties: true,
  disable_array_reorder: true,
  disable_collapse: true,
  type: "array",
  name: "some name",
  format: "tabs",
  items: {
            type: "object",
            format: "grid",
            uniqueItems: true,
            title: "RULE",
            properties: {
              path: {
                title: "ROOT Topic",
                type: "string",
                minLength: 4,
                defaut: "/hepek/"
              },
              type: {
                type: "string",
                enum: ["rc-switch", "ir-switch"],
                default: "rc-switch"
              },
              name: {
                type: "string"
              },
              message: {
                type: "string"
              },
              code: {
                type: "string"
              },
              path_would_be: {
                type: "string",
                description: "command for mqtt",
                template: "{{path}}",
                watch: {
                    path: 'item.path',
                }
              }
            }
          },
      "default": [{
        path: "/somepath/",
        name: "somename",
        code: "somecode"
      }],
    }

But i can't figure out if there is a way for "path_would_be" to be combination of previous values in same node?

Any idea???

nardev avatar Aug 10 '17 06:08 nardev

You need to pass the index to your watch statement. For example, if you are going to watch the first element in the item for the path, you should use:

watch: {
     path: 'item.0.path',
 }

penchiang avatar Sep 12 '17 13:09 penchiang

As a follow up, is there anyway to reference the particular item in the array that's doing the watching?

i.e.

watch: {
     path: 'item.i.path'
}

gkemp94 avatar Feb 11 '18 10:02 gkemp94