mrded
mrded

Reputation: 5310

How to create a multiple string field in editionView() and creationView()?

How can I create a multiple string field in editionView() and creationView()?

The object looks like following:

{
  id: 123,
  name: 'foo',
  redirects:[
    "/foo",
    "/foo-1",
    "/foo-2",
  ]
}

I need to make a form there you can write your list of redirects.

entity.editionView().fields([
  nga.field('name'),
  nga.field('redirects', '???')
]);

Thank you.

Upvotes: 0

Views: 129

Answers (1)

mrded
mrded

Reputation: 5310

As a solution, I made a template with a custom form.

entity.editionView().fields([
  nga.field('redirects', 'template')
    .template([
      '<div style="margin-bottom: 15px;" ng-repeat="item in value track by $index">',
      '<input type="text" ng-model="value[$index]" class="form-control"></input>',
      '</div>',
      '<a ng-click="value.push(\'\')"><i class="fa fa-plus"></i> Add one more</a>'
    ].join(''))
]);

It makes a form like bellow:

enter image description here

I hope there is a less hacky way of doing that.

Upvotes: 0

Related Questions