Skip to content

Get name of field referenced by eqfield #503

Open
@alinnert

Description

@alinnert

Package version eg. v8, v9:

v9

Issue, Question or Enhancement:

I use the code from the documentation to get the name of a field from its json tag. This works fine on its own.

But if I use the following:

Password        string `json:"password" validate:"required,eqfield=PasswordConfirm"`
PasswordConfirm string `json:"password_confirm" validate:"required"`

I want to create an error message like this:

Error in field "password": should be equal to "password_confirm"

But when I'm creating the error message for password I can't access the err.Field() method of PasswordConfirm which would return password_confirm. I can only access PasswordConfirm through err.Param().

I think there should be additional functions to access the values of the other/referenced field if there is such a reference. E.g.:

err.Field() // "password"
err.OtherField() // "password_confirm"
err.ReferencedField() // alternative name

Same for err.Tag(), err.Type() etc.

Or is there a way to do this now?

Code sample, to showcase or reproduce:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions