Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefinition of variable parameters #48

Open
gviabcua opened this issue Jan 17, 2024 · 6 comments
Open

Redefinition of variable parameters #48

gviabcua opened this issue Jan 17, 2024 · 6 comments

Comments

@gviabcua
Copy link

gviabcua commented Jan 17, 2024

Hello! In my plugin I'm using this code, to redefinition of variable parameters. On OctoberCMS it's working

public function boot(){
\RainLab\User\Models\User::extend(function($model) {
$model->bindEvent('model.beforeValidate', function() use ($model) {
$model->rules['email'] = 'required|between:55,60|email|unique:users';
});
});
}

On Winter.User when I replace \RainLab\User\Models\User to \Winter\User\Models\User it doesn`t work. Why?

@mjauvin
Copy link
Member

mjauvin commented Jan 17, 2024

Which version of Winter CMS are you using ?

@gviabcua
Copy link
Author

Which version of Winter CMS are you using ?

1,2,4

@mjauvin
Copy link
Member

mjauvin commented Jan 17, 2024

Try this:

   public function boot(){
          \Winter\User\Models\User::extend(function($model) {
             $model->bindEvent('model.beforeValidate', function() use ($model) {
             $model->rules['email']    = 'required|between:55,60|email|unique:users';
            }, 10);
         });
 }

(Notice the "10" which is the handler's priority)

@gviabcua
Copy link
Author

gviabcua commented Jan 18, 2024

(Notice the "10" which is the handler's priority)

Not working. The Winter.User default value is used

@gviabcua
Copy link
Author

Something strange is happening. When I pass parameters
$model->rules['username'] = 'required|between:2,255|unique:users';
it's working. But if I send

$model->rules['email']    = 'required|between:55,60|email|unique:users';
$model->rules['password_confirmation'] = "required_with:password|between:4,255";
$model->rules['password'] = "required_with:password|min:11|between:4,255";

the Winter.User default value is used

@bennothommo
Copy link
Member

I believe this would be because the Account component uses its own Validator - it doesn't use the model's validation. I can't recall why this is the case, so I'll mark it as a bug for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants