diff --git a/src/Forms/Components/MoneyInput.php b/src/Forms/Components/MoneyInput.php index f6bfe40..5a94453 100644 --- a/src/Forms/Components/MoneyInput.php +++ b/src/Forms/Components/MoneyInput.php @@ -4,7 +4,6 @@ use Filament\Forms\Components\TextInput; use Filament\Support\RawJs; -use Illuminate\Contracts\Support\Htmlable; use Pelmered\FilamentMoneyField\Forms\Rules\MaxValueRule; use Pelmered\FilamentMoneyField\Forms\Rules\MinValueRule; use Pelmered\FilamentMoneyField\HasMoneyAttributes; @@ -111,18 +110,4 @@ public function maxValue(mixed $value): static return $this; } - - public function getLabel(): string - { - if ($this->label instanceof Htmlable) { - return $this->label->toHtml(); - } - - return $this->evaluate($this->label) - ?? (string) str($this->getName()) - ->afterLast('.') - ->kebab() - ->replace(['-', '_'], ' ') - ->title(); - } } diff --git a/src/Forms/Rules/MaxValueRule.php b/src/Forms/Rules/MaxValueRule.php index d088599..35e37c3 100644 --- a/src/Forms/Rules/MaxValueRule.php +++ b/src/Forms/Rules/MaxValueRule.php @@ -30,7 +30,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void strtr( 'The {attribute} must be less than or equal to {value}.', [ - '{attribute}' => Str::of($this->component->getLabel())->title(), + '{attribute}' => Str::of($attribute)->afterLast('.')->snake(' ')->title(), '{value}' => MoneyFormatter::formatAsDecimal($this->max, $currencyCode, $locale), ] ) @@ -41,7 +41,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void strtr( 'The {attribute} must be a valid numeric value.', [ - '{attribute}' => Str::title($this->component->getLabel()), + '{attribute}' => Str::of($attribute)->afterLast('.')->snake(' ')->title(), ] ) ); diff --git a/src/Forms/Rules/MinValueRule.php b/src/Forms/Rules/MinValueRule.php index 8ec31c4..8d90464 100644 --- a/src/Forms/Rules/MinValueRule.php +++ b/src/Forms/Rules/MinValueRule.php @@ -4,6 +4,7 @@ use Closure; use Illuminate\Contracts\Validation\ValidationRule; +use Illuminate\Support\Str; use Money\Exception\ParserException; use Pelmered\FilamentMoneyField\Forms\Components\MoneyInput; use Pelmered\FilamentMoneyField\MoneyFormatter; @@ -29,7 +30,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void strtr( 'The {attribute} must be at least {value}.', [ - '{attribute}' => ucwords($this->component->getLabel()), + '{attribute}' => Str::of($attribute)->afterLast('.')->snake(' ')->title(), '{value}' => MoneyFormatter::formatAsDecimal($this->min, $currencyCode, $locale), ] ) @@ -40,7 +41,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void strtr( 'The {attribute} must be a valid numeric value.', [ - '{attribute}' => ucwords($this->component->getLabel()), + '{attribute}' => Str::of($attribute)->afterLast('.')->snake(' ')->title(), ] ) ); diff --git a/tests/ValidationRulesTest.php b/tests/ValidationRulesTest.php index 1c4595a..cb43766 100644 --- a/tests/ValidationRulesTest.php +++ b/tests/ValidationRulesTest.php @@ -17,7 +17,7 @@ public function testMinValueRule(): void }); $rule->validate('amount', 'invalid', function ($message) { - $this->assertEquals('The Total Amount must be a valid numeric value.', $message); + $this->assertEquals('The Amount must be a valid numeric value.', $message); }); } @@ -25,8 +25,8 @@ public function testMaxValueRule(): void { $rule = new MaxValueRule(10000, new MoneyInput('amount')); - $rule->validate('amount', 30000, function ($message) { - $this->assertEquals('The Amount must be less than or equal to 100.00.', $message); + $rule->validate('totalAmount', 30000, function ($message) { + $this->assertEquals('The Total Amount must be less than or equal to 100.00.', $message); }); $rule->validate('amount', 'invalid', function ($message) {