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

Add rules: different, uuid, distinct, required_if, required_with #44

Merged
merged 12 commits into from
Nov 26, 2020

Conversation

girardinsamuel
Copy link
Contributor

@girardinsamuel girardinsamuel commented Sep 28, 2020

  • Add different rule (more handy than doing isnt(equals("field")))
{
  "first_name": "Sam",
  "last_name": "Gamji"
}
validate.different("first_name", "last_name")
  • Add uuid rule
{
  "doc_id": "c1d38bb1-139e-4099-8a20-61a2a0c9b996"
}
validate.uuid("doc_id")
validate.uuid("doc_id", 4)
validate.uuid("doc_id", "4")
validate.uuid("doc_id", version=4)
{
  "users": ["sam", "joe", "joe"]
}
validate.distinct("users"). # fail
{
  "users": [
       {
            "id": 1,
            "name": "joe"
       },
       {
            "id": 1,
            "name": "sam"
       },
  ]
}
validate.distinct("users.*.id"). # fail
  • Add required_if rule

The field under validation must be present and not empty only
if an other field has a given value.

{
  "first_name": "Sam",
  "last_name": "Gamji"
}
validate.required_if("first_name", "last_name", "Gamji")
  • Add required_with rule

The field under validation must be present and not empty only
if any of the other specified fields are present.

{
  "first_name": "Sam",
  "last_name": "Gamji",
  "email": "samgamji@lotr.com"
}
validate.required_with("email", ["first_name", "nick_name"])
validate.required_with("email", "first_name,nick_name")

@girardinsamuel girardinsamuel changed the title Feat/new rules Add rules different,uuid Sep 28, 2020
@girardinsamuel girardinsamuel marked this pull request as draft September 28, 2020 22:41
@girardinsamuel girardinsamuel changed the title Add rules different,uuid Add rules different, uuid, required_if, required_with rules Sep 28, 2020
@girardinsamuel girardinsamuel changed the title Add rules different, uuid, required_if, required_with rules Add rules different, uuid, required_if, required_with Sep 28, 2020
@girardinsamuel girardinsamuel changed the title Add rules different, uuid, required_if, required_with Add rules: different, uuid, distinct, required_if, required_with Sep 29, 2020
@girardinsamuel girardinsamuel marked this pull request as ready for review October 2, 2020 08:20
@girardinsamuel
Copy link
Contributor Author

@josephmancuso ready for review :) !

Copy link
Member

@josephmancuso josephmancuso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it. Left some small requests

src/masonite/validation/Validator.py Outdated Show resolved Hide resolved
src/masonite/validation/Validator.py Outdated Show resolved Hide resolved
src/masonite/validation/Validator.py Outdated Show resolved Hide resolved
tests/test_validation.py Outdated Show resolved Hide resolved
@girardinsamuel
Copy link
Contributor Author

@josephmancuso I made the changes !

@girardinsamuel
Copy link
Contributor Author

Should we merge it in 3.0 or 2.X ?

Copy link
Member

@josephmancuso josephmancuso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me :)

@josephmancuso josephmancuso merged commit f4da403 into MasoniteFramework:3.0 Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants