Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept float (decimal values) directly in multipleOf() rule helper #13705

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

mattlibera
Copy link
Contributor

@mattlibera mattlibera commented Jul 25, 2024

Description

In Laravel, the multipleOf() validation rule accepts integers or decimals. Proper handling decimal values was addressed specifically in a Laravel framework PR after being brought up as a separate issue.

In Filament, the current signature of multipleOf() accepts either int or Closure:

public function multipleOf(int | Closure $value): static
{
    $this->rule(static function (Field $component) use ($value) {
        return 'multiple_of:' . $component->evaluate($value);
    }, static fn (Field $component): bool => filled($component->evaluate($value)));

    return $this;
}

Strictly speaking, this doesn't preclude us from using decimal values here, but doing so requires a Closure:

->multipleOf(fn() => 0.5)

Another workaround would be using rules():

->rules('multiple_of:0.5')

Either of these work just fine by proxying down to the Laravel rule, which validates as expected. Therefore, I am proposing that we also accept float into the multipleOf() helper method. Doing so would preclude the need to work around the issue as above, and also adhere to the way that a developer would be expect to be able to use this helper.

Visual changes

No visual changes included in this PR.

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

No tests currently cover this method, therefore none need modifying.
No documentation currently covers this method in that level of detail, nor do I feel it strictly necessary to call this out in the documentation.

@danharrin danharrin added the bug Something isn't working label Jul 26, 2024
@danharrin danharrin added this to the v3 milestone Jul 26, 2024
@danharrin danharrin merged commit 02b43bd into filamentphp:3.x Jul 26, 2024
11 checks passed
@danharrin
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants