decaporg / decaporg/decap-cms

Allow validation functions in config

Open
#5,350 5 comments 1 reaction 0 assignees View on GitHub
area: configuration area: extensions/widgets area: validation type: feature
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

**Is your feature request related to a problem? Please describe.**

Doing good validation is a pain. Regex is just not that easy to work with, even for things as simple as validating a url or and email address. Additionally, being limited to a single regex param prevents leveraging the JS ecosystem.

**Describe the solution you'd like**

I'd like to be able to pass a validation function when configuring fields.

```js
{
name: 'email',
widget: 'string',
validate: (val) => isEmail(val) ? true : 'Must be a real email address.',
}
```

Allowing `async` functions would be even better.

**Describe alternatives you've considered**

I thought the `preSave` hook might help, but it doesn't look like `entry` has the proper api. And even if it did, it's a really roundabout way to validate a field.

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.