Skip to content

Conversation

@System-Glitch
Copy link
Member

@System-Glitch System-Glitch commented Apr 7, 2025

References

Issue(s): closes #250

Description

  • Added validation.WithMessage() function, which overrides the language entry used to render the error message of a validator.
    • Original placeholders returned by the validator are still used to render the message.
    • Type-dependent and "element" suffixes are not added when the message is overridden.

Example usage:

func (ctrl *Controller) UpdateRequest(_ *goyave.Request) v.RuleSet {
	return v.RuleSet{
		//...
		{Path: "contents", Rules: v.List{v.WithMessage(v.String(), "validation.rules.custom"), v.Min(10)}},
	}
}

Possible drawbacks

The WithMessage syntax is not the cleanest. However, using a method instead wouldn't be possible because it would need to return itself, which wouldn't be possible with composition.

@System-Glitch System-Glitch added the feature request Request for new feature implementation label Apr 7, 2025
@System-Glitch System-Glitch force-pushed the feat/validator-override-message branch from 53a8a3c to 4a74658 Compare April 7, 2025 14:58
@System-Glitch System-Glitch self-assigned this Apr 7, 2025
@System-Glitch System-Glitch added this to the v5.6.0 milestone Apr 7, 2025
@coveralls
Copy link

coveralls commented Apr 7, 2025

Pull Request Test Coverage Report for Build 14337030354

Details

  • 14 of 14 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 97.516%

Totals Coverage Status
Change from base Build 14337018348: 0.005%
Covered Lines: 6477
Relevant Lines: 6642

💛 - Coveralls

@System-Glitch System-Glitch force-pushed the feat/validator-override-message branch from 4a74658 to 79afaeb Compare April 8, 2025 15:06
@System-Glitch System-Glitch merged commit b596ffc into master Apr 9, 2025
10 checks passed
@System-Glitch System-Glitch deleted the feat/validator-override-message branch April 9, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request Request for new feature implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation: override message

3 participants