Controlling field validation via plugin

Is it possible to convert a required field to one that is not required via a plugin?

I’m modifying the existing Conditional fields plugin (https://www.datocms.com/plugins/i/datocms-plugin-conditional-fields) so that it not only reveals fields but also hides them based on the toggle value. That’s all working well, but hidden fields are still failing validation (both in the original plugin and in my fork). What’s worse, since the fields are hidden, there’s no indication of an error other than the failure of the entry to save. Initially I thought that removing the required object from [field].attributes.validators would be sufficient, but the field still attempts to validate even when that has been removed. Is there something else that can be done to clear validation on fields that are hidden?

Thanks.

@jdozier-ezell the problem with disabling the validation is that you can do that per model, meaning that also every other model will skip the validation.

Moreover I won’t advise to skip the validation on a field or extend our API in that direction as the purpose of validations is to prevent frontend code to get overcomplicated by checking if a value is present or not every time, so that would defeat the purpose, right?

We have planned this though: Custom validation that should come soon and would give you total freedom by implementing a validation rule on your side, something that would integreate perfectly with a plugin for example!

Would that be good for you?

Thanks @mat_jack1. It sounds like that might be helpful. I wasn’t suggesting that all validation be skipped, rather just providing some way for the validation to detect whether or not a field is visible based on the toggle and then adjust accordingly. Without this, none of the fields affected by the toggle can be required. That’s not the end of the world but does introduce the possibility that fields that have been toggled on may not be filled out correctly. It would be great if Custom validation could also solve that.