decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.7k stars 3.03k forks source link

Conditional Field validation #6975

Closed clyoubi closed 8 months ago

clyoubi commented 8 months ago

I'm proposing a feature for conditional validation in Netlify CMS.

What type of feature or enhancement is this?

This is a CMS Administration and Configuration enhancement.

What is the use case for this feature are you envisioning?

In the current setup, Netlify CMS does not support conditional field validation in the config.yml. Adding this feature would allow certain validations to be turned on/off based on the boolean value of a specified field. This will be beneficial in cases where different validation rules are needed under different conditions.

Have you considered any alternative solutions or workarounds?

Currently, one workaround could be implementing dynamic validation checks in the building process of the application. This would require handling outside of Netlify CMS using JavaScript or the coding language used for the site. While this works, it complicates the process and is not as user-friendly or efficient as having the capability directly in Netlify CMS would be.

martinjagodic commented 8 months ago

@clyoubi please describe what you mean by conditional field validation. Also provide some mock screens if applicable.

clyoubi commented 8 months ago

Hello @martinjagodic, I'm working on a feature for one of our Hugo websites. We have old websites where we didn't apply a pattern validation and they've been saved sometimes with weird unconventional URLs and went live. Now we'd like to fix it by letting the content decide if the pattern validation should be applied or not, the most common case when editing an existing page is not to force the user to change the URL for SEO reasons of course.

image

martinjagodic commented 8 months ago

This seems like a niche requirement, so I suggest you go with the workaround. If more people find this useful, we could accept a PR.