-
Notifications
You must be signed in to change notification settings - Fork 33
Custom fields #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom fields #40
Conversation
|
Some immediate questions that come to mind is how is the backend handling this, say with pagination, filtering, field selection, ect. |
|
|
||
|  | ||
|
|
||
| Since we are not introducing any new field type, the content type schema won’t change in structure. This also means the custom fields have the same options as the native ones (ex: required, unique, etc), as well as some additional validation rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what you mean by as well as some additional validation rules ?
Are you referring to validations in the content type builder in order to save a custom field or adding custom validations for a custom field in the content manager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter. For instance, insuring that a URL for a video is actually from Youtube in the case of a video embed. Or validating that a string is a URL, etc. Is it clearer?
The custom fields feature is more about the "frontend". |
|
Very excited about this feature, loved the presentation at today's conference. I love that you have already identified some use cases and are building ready to plug Custom Fields. What I'd love to know is if like plugins we'll be able to code our own custom fields and consume them in the Content Builder? |
Hi Aurélien, |
Yes you will be able to! |
|
This is very exciting. Do you have any idea as to when this feature will be available? |
|
Any chance we might see conditional fields in this feature? Something like Fields B and C are only shown if Boolean Field A is true, for example? Would it enable things like enumeration fields with labels? Red | #FF0000 Where only the label is shown in the select field in the admin panel, but the value is saved for the REST response. |
|
@rgesulfo, @soupette thank you that's beyond exciting. Coming from the WordPress + ACF Pro combo what I've been missing is a few fields that I have a use for in most projects. So far I had to use turnarounds in order to meet my expectations with Strapi. Here are a few of the ones I'm thinking of from an editing experience perspective:
I have created some plugins for internal use on projects and would be happy to help develop these custom fields. Another thing that I think we should consider is if Custom Plugins could also rely on Custom Fields, for example using the new Color Field inside a custom-built Admin page. |
Probably not in this feature but that is one feature request that comes up quite often :) |
|
This is nice! I'm curious about the way the data will be stored, but I think that will be added later. |
These are good points. We don't have a clear answer yet (some of the solution could come from supporting other field types/formats). To move forward as quickly as possible on this, we are thinking to forgo them in the list view for now. Or to treat them as Strings (ex: filtering hex values or google maps URLs). We could also leave the developers to handle how their custom fields should be handled by the filters and search. @soupette @alexandrebodin feel free to jump in on this tech topic :) Thanks |
Without overpromising anything, we can tell you the Expansion squad will start working on a beta version this quarter :) We are hoping to share more updates in the coming weeks. |
That's a very interesting topic indeed. We're hoping to keep things simple for now without worrying too much about how data is stored. At first, it could be JSON only. But later on, we could potentially store meta data (ex: title, duration, preview, etc) from a Youtube URL to not have to fetch the data all the time the field is displayed and be able to serve this content through our endpoint. Feel free to share some ideas on the matter if you want :) Thanks for your question. |
|
Hello all, I would like to add my 2 cents to this conversation. I think that in terms of implementation, Strapi should look at GraphCMS (https://graphcms.com/docs) which is very close in terms of management (code).
Color (https://graphcms.com/docs/api-reference/schema/field-types#color) which would have the following format: type Color {
hex: Hex! # Returns a String in the format of #ffffff
rgba: RGBA! # r, g, b, values as RGBAHue!, and a as RGBATransparency!
css: String! # Returns in the format of rgb(255, 255, 255)
}Location (https://graphcms.com/docs/api-reference/schema/field-types#location) which would have the following format: type Location {
latitude: Float! # Geographic coordinate (north-south position on Earth)
longitude: Float! # Geographic coordinate (east-west position on Earth)
}Enumerations (https://graphcms.com/docs/api-reference/schema/field-types#enumerations) but I'm not convinced by the latter The addition of the first 2 would allow to satisfy the Color picker and Map usecase. For the data storage, they will be put directly in the database since it is static data. Now for the videos, e-commerce usecase I propose to keep the plugin approach which can add fields that are just extensions of the base fields. GraphCMS calls them UI Extensions (https://graphcms.com/docs/ui-extensions/field-extension/quickstart) I think we could take up their extension statement: const declaration = {
extensionType: 'field', // In strapi it will be a plugin type maybe, I don't know
fieldType: FieldExtensionType.STRING, // In strapi it be one of the default type
features: [FieldExtensionFeature.FieldRenderer], // in strapi it where the plugin will be display or features of the plugin
name: 'Hello UIX World', // In strapi, it is the plugin name
config: { // In strapi, it is the plugin config to be able add custom key etc. Only issue with that it is should be stored securely
API_KEY: {
type: 'string',
displayName: 'API Key',
description: 'API Key for this UI Extension',
required: true,
},
},
};Configuration display in GraphCMS All the management of UI could be managed using the Strapi design system and some react context. You can read more here and examples here With UI Extension we can handle usecase for Video and E commerce. The data will be stored directly to the database and because it is a extension of some type, the backend layer will not change.
Based on the transform usecase above, UI extension for e-commerce solve one part of the problem. Indeed, most of the time when we use this kind of plugin, we only store the ID and on the backend, we do the fetching of the linked data to be sure to always have the last update. Remote field solve the URL usecase in the RFC. First, we define a Remote Type Definition {
// In GraphCMS it is a GraphQL schema but in Strapi it will be a content type schema for example
definition:
"type CommerceLayerSimple { code: String, name: String!, formatted_ammount: String!, available: Boolean }
displayName: "Commerce Layer Simple", // Name in the plugin maybe ?
description: "Information from the Inventory Management",// Description in the plugin maybe ?
}Then, we are adding a Remote Field that we call Inventory {
apiId: "inventory", // Name of the Field in plugin maybe ?
displayName: "Inventory", // displayName in the plugin maybe ?
remoteConfig: { // Configuration to execute the HTTP call
method: "GET",
payloadFieldApiIds: ["productId"], // an existing Strapi field (in the content where the the remote custom field is defined) that is used to pass its value as an argument to the remote API call
returnType: "CommerceLayerSimple", // The return type of the remote field. In this case, it is our custom CommerceLayerSimple type. It is defined above
url: "<YOUR_REST_ENDPOINT_HERE>", // Url to the endpoint
// or we could add request function and let the developper handle the stuff
request:async(payloadFieldApiIds): CommerceLayerSimple =>ReturnYourPromise
},
}Once an API call is issued to the Strapi backend and you request a remote field. Strapi will execute the remote config HTTP call and the JSON response contains fields with those names and types, the values of those fields will be returned, from CommerceLayer, in the Strapi response of your content API, without the content itself being created and/or duplicated into the CMS. I hope with that we could be make Strapi perfect for all extension. Thanks for reading |
|
Hello guys - any predictions when this feature may be added to main version of Strapi? 🤔 This has been something I've been thinking about for a long time! :D |
Sooner than you think 😉 |
|
Hey @rgesulfo @derrickmehaffy @soupette here are some questions:
|
|
I have a use case with https://github.com/strapi-community/strapi-plugin-local-image-sharp We may want to create a new field based on an image field (like slug is bound to a text field) to create different formats. In this field, we can select multiple format on the admin ui (different size, in different format, etc...). Those settings should be set on the Content-Type Builder and not on the Content Manager. Like we select types of files that can be uploaded. This can not be done in a stand-alone package since we need to perform these image manipulations on server. We also need to alter responses to include our new images data |
Hi Sacha, Thank you for sharing your use case. It definitely picked my brain so much that I had to make some designs to look at how we could accommodate it in our vision. Let me know if this is clear enough and could solve what you are describing. Thank you for your help :) |
|
I like this idea but this is just ui level field. What if we want to support database types? Like geometry and geography type? If CTM give access to the plugins to validate and convert field data it will be perfect. |
|
This pull request has been mentioned on Strapi Community Forum. There might be relevant details there: |
|
Closing this RFC as we got enough feedback and merged the implementation one :) |
Disclaimer: This RFC is at an early stage and covers only high-level requirements. We are hoping the community can help us identify and spec the technical requirements. Thank you in advance for your help.
You can read it here.