Blueprint type: list new data on top of array

Hi!

Is it possible to add a new data item on top of the array than at the end when adding it via blueprint “type: list”? I didn’t found a param in reference list:

I would be thakful for an hint!

Try adding ordering to your added last field

ordering@: -1

thank you for your answer. that only works with fields. I want to set whole new added data items on top of the list because we have performance problems when data lists are too long.

Oh, I totally misunderstood you. Sorry

Also, this solution should work, but I’m not sure how to extend plugins themes templates. I’ll create PRs for both Admin and Flex objects plugins, because I think it would totally make sense, that “Add item” button at the top, should add item to the top and bottom button - to the end.

Beware - if you change templates as I suggest here, most likely you’ll lose functionality after Admin or Flex Objects updates, unless my future PRs get approved and merged.

So, the solution is really very simple. Two files to change one string in each. Note, that there will be two matches in each file, but I suggest to change only the first one - that would be top button - and leave the second one (bottom button) as is.

  1. user/plugins/admin/themes/grav/templates/forms/fields/list/list.html.twig
    Line 59. Find data-action-add="bottom" and change to data-action-add="top"

  2. user/plugins/flex-objects/templates/forms/fields/list/list.html.twig
    Exactly the same - line 59: data-action-add="bottom" >> data-action-add="top"

Most likely what you need is only in one of these files. I don’t know where you want to change behavior - Admin default forms or Flex Objects forms

I see in the docs, default behavior is, that button is shown only at the bottom, so you can define for list field to show only at the top or both:

controls: [top|bottom|both]

If someone knows how to extend these templates, please feel free to fill in, but I see there’s only one main block, so that would mean copying full template, which later wouldn’t get updates.

PRs are on the way. Will add links here later


Edit:
Admin PR and Flex Objects PR

1 Like

Yes, adding control: top only adds the add button to the top of the form but the element is still at the end of the list.
I want this just for one data type in admin panel. not for pages or other types. I think I have to edit the list.html.twig in my own plugin or do an action in onAdminSave Hook.

Thank you for your help!

I’ve updated both plugins PRs and added a PR to the docs. When (if?) they get approved, then in some release you’ll be able to set which buttons adds item where by field basis.

1 Like

Admin 1.10.4 has the feature. Check List field placement property description

1 Like