Strapi Version: v1.22.17
Hello all, I am going to build an inventory management system with Strapi for my client. However, I am still not so sure if I can implement a particular requirement from them after studying the basics of Strapi. They want the ability to add an arbitrary number of text fields to a particular collection type. Is it possible that I could write that logic for that and provide an API for the frontend?
Hi Patrick, yes you can achieve this by creating a component that is a single text-field, and then adding that component as a named repeating component to a single or collection type.
You could also have name->value pairs by extending the component to have two text fields.
Hope that helps.
@knowncolor sure that helps! Sounds like I haven’t used to the content manager yet
Further to the question, to my knowledge, only admin users could access the content manager in a production environment, but in my case, I don’t even want their “admin” user (which should be under the “users” category in Strapi’s language) to mess with the other fields in the collection type, I want them to just able to add and remove. I probably would make a custom inventory managing frontend, but with this “add new fields” function. How could I go further with this “add components to dynamic zone” setup?
Hi @Patrick_Lee, the users for the admin panel are different from users that might sign up on your web app.
To limit updates to a certain field for a certain user role you will need to create custom endpoints.
That branches into two questions to me now.
Should the logic behind the custom endpoint I will be implementing make changes to the database directly?
What I do is in fact already can been done by content manager, and I understand that content manager is considered as a default plugin that comes with Strapi. Should I extend the plugin or can I make use of the existing functions (or even endpoints) of the content manager instead of coding that from scratch?
Hi @Patrick_Lee, somethoughts…
Your custom endpoint can interact with the database using the entity service, or the lower level query api.
Strapi makes available a REST API for all your data by default, as well as the admin UI plugin API so its up to you. The admin UI gives you a lot for free vs building a web UI.
@knowncolor thank you very much for the directions! I am now looking at adding the fields in the dynamic zone by the default APIs with a proper admin user. I just suddenly realise that I could let the system admin login as an admin user without going to the default /admin page by making use of the admin login API.