#How do I only save changes to a custom component's value on save? [v3.0.0-beta.20]
11 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
- Stripe Plugin - Sync
- React Hooks - useFormFields
- React Hooks - useForm
- Redirects Plugin
- Swap in your own React components - Collections
Community-Help:
Thanks @drifting gorge .
src/fields/TestField/Testfield.tsx:
'use client';
import {useField} from '@payloadcms/ui/forms/useField'
function TestField({path}) {
const {value, setValue} = useField({path})
const onClick = function () {
setValue(value + '*');
}
return (
<div>
<button onClick={onClick}>Click me</button><p>{value}</p>
</div>
)
}
export default TestField
src/fields/TestField/index.ts:
import Component from './TestField'
export const TestField = (name) => {
return [{
name,
type: 'text',
admin: {
components: {
Field: Component,
},
},
}]
}
src/collections/Examples/index.ts:
import type {CollectionConfig} from 'payload/types'
import {TestField} from '@/fields/TestField'
export const Examples: CollectionConfig = {
slug: 'examples',
admin: {
useAsTitle: 'name',
},
fields: [
{
name: 'name',
type: 'text',
required: true,
},
...TestField('columname')
],
}
@minor raft Can you add "type='button'" to your button
Any buttons without that type will be treated as Submit buttons IIRC
Which will submit the doc through the normal means
🤦♂️ Thank you, much appreciated!
Glad your issue was resolved! :tada: If you want to help make payload better, please give us a :star: on GitHub and review us - It helps us a lot.
🌟 Star Us on GitHub
👍 Review Us
Did that solve it?