Hi all, I'm trying to update an array field from another custom UI component I'm creating.
The field definition:
{
name: 'tickers',
type: 'array',
fields: [
{
name: 'symbol',
type: 'text'
}
],
}
How I'm trying to update the field's value:
const myField = useField({ path: 'tickers' });
myField.setValue([ { symbol: 'test' } ]);
Sadly enough nothing happens, and no error is thrown.
However... when logging
myField.value
it logs the array length of the field, not the actual value itself.
Something else I tried:
const [ allFields, dispatchFields ] = useAllFormFields();
dispatchFields({ type: 'UPDATE', path: 'tickers', value: [{ symbol: 'test' }] })
But sadly... no luck there.
Bump 👀
@jmikrut here you go
nice
will cross-post my answer here:
one note, we are about to release changes that make it a LOT easier to programmatically update arrays
but in the meantime, i wrote up an example for how to do it here:
Ah, in the meantime I'll try that! thanks @jmikrut 🙂
of course! and keep an eye out, lots of new arary stuff coming soon
Sweet! can't wait
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.