UseMuffin/Slug

Multiple-column display field: please allow columns to be empty

ssmeding opened this issue · 4 comments

My user table contains separate fields for first, middle and last name.
First and last name are required, middle name is optional.

Unfortunately, when I want to use SlugBehavior and configure it to have a displayField based on these three fields, they al become mandatory in forms and saving. So I cannot add users without filling in a middle name.

I think when there are multiple columns in the displayField config value and from the default model validation at least one of them is required and not allowed to be empty, buildValidator should not add any extra validation.

I did notice this thread:
#23

I will for now disable buildValidator as suggested here. But I'm still wondering if the default behavior of this method could be improved in a way it wouldn't be necessary to override the implementedEvents option.

Toggling the default validator will require to set a config option one way or the other, and cakephp is purposefully built to handle customized validation. I believe it's currently pretty much at it's simplest form.

I will for now disable buildValidator as suggested here. But I'm still wondering if the default behavior of this method could be improved in a way it wouldn't be necessary to override the implementedEvents option.

You could do that in the behavior code by checking:

Implement it and do a PR :)

ADmad commented

Modifying the implementedEvents config to disable the validations isn't too much effort. As pointed even if an alternate way was provided you would still have to modify default config. So I don't think any change is necessary. I'll just update the docs.