json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

How work "condition"? #961

Closed person2713 closed 6 years ago

person2713 commented 6 years ago

I don't understand how work "condition". Can you explain me, please? And how erase "undefined" from {"key": "Objects[].object.attributes[].value"}

`{
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "Objects": {
     "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "object": {
            "type": "object",
            "properties": {
              "objectId": {
                "type": "string"
              },
              "attributes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "attributeId": {
                        "type": "string"
                    },
                    "value": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
"form": [
      {"key": "name"
      },
      {"key": "secname",
          "condition": {
                        "functionBody":"try { return model.name=='test'} catch(e){return false}"
                    }
      },
      {"key" :"Objects",
        "type": "array",
          "items": [
              {"key":"Objects[].object",
               "items": [
                    {"key": "Objects[].object.objectId",
                        "htmlClass": "col-xs-6"
                    },
                    {"key": "Objects[].object.objectName",
                    "htmlClass": "col-xs-6",
                     "condition":
                     {
                        "functionBody":"try { return model.Objects[arrayIndex].object.objectId=='111'} catch(e){return false}"
                    },
                     "readonly": "true"
                    },
                    {
                        "key": "Objects[].object.attributes",
                        "type": "array",
                        "items": [
                            {"type": "section",
                              "htmlClass": "row",
                              "items": [
                                  {
                                      "type": "section",

                                      "items": [
                                          {"key": "Objects[].object.attributes[].attributeId"}
                                          ],
                                          "htmlClass": "col-xs-1"
                                  },
                                  {
                                      "type": "section",

                                      "items": [
                                          {"key": "Objects[].object.attributes[].attrbuteName",
                                            "condition": "",
                                            "readonly": "true"
                                            }
                                          ],
                                          "htmlClass": "col-xs-1",
                                  }
                                  ]
                            }
                            ,
                            {"key": "Objects[].object.attributes[].value"}
                        ]
                    }
                ]
              }
          ]
      }
    ]
}`

I have to add items that I add on layout or it will work without this with condition?

Anthropic commented 6 years ago

@person2713 are you sure you didn't post in the wrong place again? That form code doesn't loook like ours.