Displaying input types within a custom input type (ngx-formly)

16 views Asked by At

I'm trying to create a custom input type (multiField) which displays multiple arbitrary inputs within itself. It seems like the formly-field directive should make this reasonably doable. I should just be able to put a list of fields inside the JSON element for the multiField element and have them show up.

The problem is that this only seems to work if I put those fields in a fieldGroup property. If I put them elsewhere, a bunch of properties don't get tacked on and so the fields don't work. (Obviously I'm pointing the template to where the fields are in each case.)

This way works:

{
  type: 'multiField',
  fieldGroup: [
    // some fields
  ]
}

This way does not:

{
  type: 'multiField',
  templateOptions: {
    fields: [
      // some fields
    ]
  }
}

Normally I would just do it the first way because obviously that's what works. But I'm trying to upgrade an old system from angular-formly, and some of the existing data does it the second way. So I'd really like to make that work too.

Live demo: https://stackblitz.com/edit/ngx-formly-ui-bootstrap-4jiein?file=src%2Fapp%2Fapp.module.ts

0

There are 0 answers