We just have that control in our code: import { Text, Checkbox, Select } from 'payload/components/forms';
<Checkbox name={controlName} label={label} required={isRequired} /> Could we use some additional attribute to set that checked initially?
@jacobsfletch
Is this a custom field component? In that case you could use
defaultValue: true
in your config as described here
https://payloadcms.com/docs/fields/checkbox#config
Otherwise if you're importing Payload's checkbox for another use, it's not quite setup for that yet. This is a roadmap item described here
https://github.com/payloadcms/payload/discussions/293which we plan on tackling with moderate priority.
Basically we need to allow the checkbox to be externally controlled. Right now it ties into form state but we need to detach it. We've already done this for the
Text
,
Textarea
, and
Upload
fields, just need to get to the rest.
This checkbox is in AdminView that is invoked with some url that is that in config file. I could use defaultValue, but to what value to set that?
Yes we are setting using initial values for form when state is saved into database. But when started to create, it is set to false.
Not a huge deal, we could just allow the user to click and check. When submitted, state is saved into database.
Ok then you should be able to use
defaultValue: true
in your checkbox config
Not really - I don’t know name of this field when config is created. When we are selecting property required, for example, check box is created but the user need to click that checkbox, not a huge deal.
Ok so it does sound like this falls under the latter, which means we just need to allow support for external control of the checkbox field
I think we just need to export the checkbox input, like we do for the text field
We have to detach it from form context to allow to be controlled via props.
This is not a huge deal at all - it is ok for user to select checkbox to be added under the form and click to be checked.
Yes, checkbox input has checked property, but it is inside checkbox and does not work under the form. I mean when we press submit, fields and data have the state of all controls, so we are using checkbox for that to work properly.
What do you mean related to text field? Could text field to be controlled via properties?
I was thinking you were trying to render a custom field component, but I’m not sure if you are
We could use initialData, for form, but may be there is a different way, like to use property by text field.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.