chenquincy/vue-dynamic-form-component

Arrays with different kind of items inside

scb00 opened this issue · 2 comments

scb00 commented

Hi, thank you for this library, it is really good!

Would it be possible to add different types of items in the same array? For instance:

descriptors: {
  array: {
    type: 'array',
    label: 'array label',
    defaultFields: [
      {
        type: 'object',
        label: 'Object item',
        fields: {
          boolean: { type: 'boolean', required: true },
          string: { type: 'string', required: true },
        }
      },
      {
        type: 'string',
        label: 'String item'
      }
    ]
  },
}

And then, instead of a single [+ Add item] button, there would be one button for each different defaultField item, like this:

image

Would something like this be easy to implement? It would add a lot of flexibility to the form.

Thank you.

@scb00 Sorry for the late reply. Unfortunately, it don't support this feature now. But, it is not very difficult to implement. I will try it this weekend(maybe later than it), pull requests are always welcome too.

@scb00 I found that I misunderstand what you mean. You feature will not be implement, it will make the array items unpredictable so the form cannot be valid correctly. But another feature will be supported at future:

descriptors: {
  array: {
    type: 'array',
    label: 'array label',
    fields: {
        '0': {type: 'string'},
        '1': {type: 'boolean'}
    }
  },
}

Still only a single [+ Add item] button in this feature.