decaporg / decaporg/decap-cms

Allow specifying a dynamic default value via a function

Open
#1,407 22 comments 4 reactions 0 assignees View on GitHub
pinned
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

**- Do you want to request a *feature* or report a *bug*?**

*feature*

**- What is the current behavior?**

The default value of a field has to be a fixed string/number/boolean (depending on the field type).

**- What is the expected behavior?**

It would be great to be able specify a function that would return the desired value (maybe even allow it to return a promise for it, for even greater flexibility).

My use case is that I would like to generate `uuid`s for my collection entries and editor components, and store them in a field with `widget: 'hidden'`.

Would be great to be able to do something like:

```js
CMS.registerEditorComponent({
// ...
fields: [{
name: 'uuid',
label: 'UUID',
widget: 'hidden',
default() {
return generateUuid();
}
} /*, ... */ ]
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.