0

I'm trying to generate a form which will have multiple vehicles and each vehicle should have multiple people inside it.

I tried to do it by using an array inside another array. But for some obscure reasons it's not working.

This is what I want: https://i.sstatic.net/PmxF3.png

This is what I have (so far):

Form:

[
  {
    "key": "vehicles",
    "items": [
      "['vehicles'][]['plate-number']",
      "['vehicles'][]['color']",
      {
        "key": "people",
        "items": [
            "['vehicles'][]['people'][]['name']"
        ]
      }
    ]
  }
]

Schema:

{
  "type": "object",
  "properties": {
    "vehicles": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "plate-number": {
            "title": "Plate number",
            "type": "string"
          },
          "color": {
            "title": "Color",
            "type": "string"
          },
          "people": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string",
                  "enum": ["dr","jr","sir","mrs","mr","NaN","dj"]
                },
                "name": {
                  "title": "Name",
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}

Edit: stefankmitph's answer solvers my problem. Thank you!

But something weird is happening: a new object person is added at the same level of vehicles. Also, when I fill a person's information and then delete this person the models is not updated.

4
  • Are you getting any errors? What is not working? Commented Apr 5, 2015 at 8:20
  • Could you show the code that generates that? Commented Apr 5, 2015 at 9:47
  • can you post please, what html code you tried till now? Commented Apr 5, 2015 at 10:18
  • 2
    @BrennoMartins you edited stefankmitph's answer solvers my problem, then you should accept that answer so that it will help other users with same problem like you faced. Commented Apr 5, 2015 at 19:35

1 Answer 1

1

The schema you provide does not add a property 'gender' (as shown in your picture link). So I took 'title' instead of 'gender':

[
  {
    "key": "vehicles",
    "items": [
      "vehicles[].plate-number",
      "vehicles[].color", {
          "key": "people",
          "type": "array",
          "title": "People",
          "items": [
              "vehicles[].people[].name",
              "vehicles[].people[].title"
              ]
      }
    ]
  }
]

I hope this is what you're looking for! Note: Tested with Schema Form Example Page

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.