Using Payload Form Field Components in your custom components #360
-
I'm trying to build out some custom form components, but I want them to be styled like the default payload components. I am able to import the components, but they don't come with an "onChange" handler, meaning I can't get the data out of them... has anyone successfully done this? I didn't see anything in the docs about it. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 14 replies
-
Have you seen the blog post on custom field components? https://payloadcms.com/blog/building-a-custom-field This goes a lot more in depth than what we put in the docs. If you are importing fields directly from Payload, you might not have access to everything you need. Instead you can import the styles and use the Does this help? |
Beta Was this translation helpful? Give feedback.
-
Hey @ninahorne — I see what you're looking to do. I have been thinking about this myself actually in another project. We could extend built-in field components like If either Then you could benefit from the exact same components that Payload UI uses. Alternatively, right now, Payload SCSS is already exported and able to be re-used in custom components. There is a This approach would be easy enough and probably more performant for simple components like text inputs, but for For Is there a route that you would prefer? We could work something up pretty quickly I'd expect! |
Beta Was this translation helpful? Give feedback.
-
Okay @ninahorne version Your original request was for It works exactly as you might expect by exposing the Let us know if you have any troubles wiring this in! |
Beta Was this translation helpful? Give feedback.
-
Thank you!
…On Mon, Dec 20, 2021 at 10:44 AM James Mikrut ***@***.***> wrote:
Hey @ninahorne <https://github.com/ninahorne> — we just published a beta
version where you can now import *solely* the inputs of the built-in Text
and Select components. We'll be exposing more over time but for now these
two should get you started!
If you yarn add ***@***.*** - you'll then be able to import the
inputs themselves like this:
import { TextInput, SelectInput } from 'payload/components/forms';
This should be what you need!
—
Reply to this email directly, view it on GitHub
<#360 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACTULVCBO3F5CCI4SWHAM4LUR5FMBANCNFSM5HWKURSA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
Okay @ninahorne version
0.13.6
deploys these new features into theText
,Textarea
,Upload
, andSelect
components.Your original request was for
Select
, so here's an example what a custom select component might look like (and here's the config for that field).It works exactly as you might expect by exposing the
onChange
andvalue
for you to manage freely. If you want this value to continue saving to the document (as the example illustrates), you can still sync it with context via theuseField
hook.Let us know if you have any troubles wiring this in!