Skip to content

Validating custom entry field through custom validator rules not working #16597

Answered by brandonkelly
jamesmacwhite asked this question in Q&A
Discussion options

You must be logged in to vote

RequiredValidator will check if the value is null, [], or '' by default. So yeah you’d need to override its isEmpty property with a custom callback that returns !$value->exists().

Should the required validator rule just work on a custom entry field without isEmpty being modified like the second example? As it wouldn't work without me modifying the isEmpty value,

There’s no way to automate it since the required validator has no idea that it’s validating a custom field; field:customField is just some arbitrary attribute name that it’s going to use to get the value from the model being validated ($value = $model->$attribute).

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jamesmacwhite
Comment options

@brandonkelly
Comment options

Answer selected by jamesmacwhite
@jamesmacwhite
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants