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

isnt and is_in validation message error #22

Open
nioperas06 opened this issue Dec 24, 2019 · 7 comments
Open

isnt and is_in validation message error #22

nioperas06 opened this issue Dec 24, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@nioperas06
Copy link
Contributor

users = User.all()
...
isnt(
       is_in('email', users.pluck('email'))
),

The email must not contain an element in <orator.orm.collection.Collection object at 0x10752e198>
Having something this would be better The email has already been taken. or The email is taken.

@josephmancuso josephmancuso added the enhancement New feature or request label Dec 24, 2019
@girardinsamuel
Copy link
Contributor

girardinsamuel commented Aug 8, 2020

It's a bit tricky with this one because you migth want to use isnt(is_in()) for multiple cases :

  • You want to ensure that a value is not in a list => the error message would be in case of error : "value Y is in list X"*
  • You want to ensure that email is not used by registered users => the error message, as you said, would be : "email is already taken".

We want to be able to use both I guess.

Maybe solutions are :

  • override messages in your project for this validation rule (if not possible then it's a good feature to add because some people would want other messages for their project !)
  • create a specific validator for this case and try to abstract User model fetching ... ?

@nioperas06 what do you think ?

@josephmancuso
Copy link
Member

We could just add a new validation rule called not_taken('email') and tie into the database somehow like not_taken('input_field', 'table.column') so would look something like not_taken('email', 'users.email')

@girardinsamuel
Copy link
Contributor

Yes why not ! I'll try to do it ;)

@josephmancuso
Copy link
Member

I'm not 100% sure how this will be done with connecting to a database within this project

@josephmancuso
Copy link
Member

@girardinsamuel thinking more about this it might need to be an import from the masonite project.

@girardinsamuel
Copy link
Contributor

Yes that could work.
I was thinking/experimenting about converting users got from path in the validation rule, into a n import from Masonite.

@girardinsamuel
Copy link
Contributor

For further information see #43.
It will be added into Masonite core, so this issue should now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants