0

I'm trying to figure out a way to NOT show the remove buttons for embedded lists in ng-admin.

My goal is to show and edit these nested items in editionView, but you should not be able to remove any nested items.

users.editionView()
  .title('Edit user')
  //... bunch of fields here.
  .nga.field('context', 'embedded_list')
      .targetFields([
        //... more fields, and then further nested fields:
        nga.field('categories', 'embedded_list')
          .targetFields([
            nga.field('title')
            nga.field('score')
          ])
      ])
  ]);

The problem I get here is that if I set the fields labeled as 'embbeded_list' to .editable(false), then all its nested fields also become uneditable.

I want to edit the fields, but a user should not be able to remove a whole item."title" and "score" together is what I mean by an "item", since there can be any number of these, and same for "context".

Thanks for any help in advance!

  • I solved it myself with nga.field('target').cssClasses('button-override') Then target the specific classes in css: .button_override div.remove_button_container { display: none; } This is clearly a workaround though. – Henrik Eliasson Sep 23 '16 at 07:49
  • Did you try overriding the template with `.template()`? The current template is a good starting point: https://github.com/marmelab/ng-admin/blob/master/src/javascripts/ng-admin/Crud/field/maEmbeddedListField.js – François Zaninotto Sep 28 '16 at 11:54
  • @FrançoisZaninotto That's what I should've done. To be honest I did not find the template at the time, and found it tedious to figure out how to write my own embedded_list template. You should write that as an answer, and I'll accept it as the correct answer. Maybe make the default templates more readily accessible in the documentation as examples as well? – Henrik Eliasson Sep 28 '16 at 16:12

1 Answers1

0

Try overriding the template with .template(). The current template is a good starting point:

https://github.com/marmelab/ng-admin/blob/master/src/javascripts/ng-admin/Crud/field/maEmbeddedListField.js

François Zaninotto
  • 7,068
  • 2
  • 35
  • 56