Skip to content

Exclude If doesn't work on boolean and nil parametr #1310

@DarkReduX

Description

@DarkReduX
  • I have looked at the documentation here first? Yes
  • I have looked at the examples provided that may showcase my question here? Yes in doc.go too

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

exclude_if doesn't work with 'nil','true','false' values in provided parametrs

Examples:

// exclude the field if the Field1 is equal to the parameter given:
Usage: excluded_if=Field1 foobar

// exclude the field if the Field1 and Field2 is equal to the value respectively:
Usage: excluded_if=Field1 foo Field2 bar

Code sample, to showcase or reproduce:

type Struct1 struct {
  Field1 bool
  Field2 *string `validate:"excluded_if=Field1 false"`
}

type Struct2 struct {
  Field1 bool
  Field2 *string `validate:"excluded_if=!Field1"`
}

func main() {
ctx := context.Background()

  vldtr := validator.New()
str := "321321"
vldtr.StructCtx(ctx,Struct1{false, str})

vldtr.StructCtx(ctx, Struct2{false, str})
}

// Output: !panic recovered: Bad field type *int64

Output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions