Handle length validator with procs, improve validators support#1859
Merged
carlosantoniodasilva merged 4 commits intomainfrom Jan 5, 2026
Merged
Handle length validator with procs, improve validators support#1859carlosantoniodasilva merged 4 commits intomainfrom
carlosantoniodasilva merged 4 commits intomainfrom
Conversation
Devise changed their password validations to use a proc for minimum/maximum for additional customization, but that apparently broke SimpleForm minlength/maxlength logic since it wasn't handling that. Instead of implementing it custom by checking for the value responding to `call` like we do for a couple of other validators, I went with the route of copying over the `resolve_value` implementation added to Rails 7.1 that handles all the possible scenarios for procs / send / etc, which allows different ways of setting up the proc. Closes #1858
The shared logic can be reused to handle numericality and format validators as well, instead of custom handling for each, so it better matches Rails own implementation.
It expects the record to be passed as argument to the proc. Rails 7.1 added the ability to pass a proc without any args.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Devise changed their password validations to use a proc for
minimum/maximum for additional customization, but that apparently broke
SimpleForm minlength/maxlength logic since it wasn't handling that.
Instead of implementing it custom by checking for the value responding
to
calllike we do for a couple of other validators, I went with theroute of copying over the
resolve_valueimplementation added to Rails7.1 that handles all the possible scenarios for procs / send / etc,
which allows different ways of setting up the proc.
Expand usage of the shared
resolve_valueimplementation acrossthe board, so other validations like numericality and format apply the
same logic to better match Rails behavior.
Closes #1858