Skip to content

Bail on first error #89

Open
Open
@jcobhams-cp

Description

@jcobhams-cp

Would it be possible to return the error bag on the first failure as opposed to running all the rules.

  1. Bail when the first rule in a ruleset for a field fails
    example:
rules := govalidator.MapData{
		"email": []string{"required"},
		"password": []string{"required"},
		"some_field": []string{"bail", "required", "in:something,somethingelse"},
	}
  1. Bail when the first rule for the entire validation fails.
opts := govalidator.Options{
		Request:         r        // request object
		Rules:           rules,    // rules map
		Messages:        messages, // custom message map (Optional)
		RequiredDefault: true,     // all the field to be pass the rules
                 BailFirstError: true //returns the error bag with only one item
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions