Add custom rule to custom input

Hey all, I have a custom input that is working perfectly, but I want to add a custom rule set. Currently my working code is like this:
OrcidInput::make('orcid')
->rules(['required', new OrcidChecksum])
->columnSpan(6)
->required(),
OrcidInput::make('orcid')
->rules(['required', new OrcidChecksum])
->columnSpan(6)
->required(),
I want to add this rules set to my OrcidInput.php class, so i don't need to repeat the rule everytime i create another OrcidInput. Current OrcidInput:
class OrcidInput extends TextInput
{
//@TODO: add validation logic incl. checksum for last character
protected string $view = 'forms.components.orcid-input';

public function getLabel(): string|Htmlable|null
{
return 'Full ORCID iD';
}
public function hasMask(): bool
{
return true;
}

public function getMask(): ?Mask
{
$mask = new Mask();

$mask->pattern('****-****-****-****');

return $this->evaluate($mask, [
'mask' => app(TextInput\Mask::class),
]);
}
}
class OrcidInput extends TextInput
{
//@TODO: add validation logic incl. checksum for last character
protected string $view = 'forms.components.orcid-input';

public function getLabel(): string|Htmlable|null
{
return 'Full ORCID iD';
}
public function hasMask(): bool
{
return true;
}

public function getMask(): ?Mask
{
$mask = new Mask();

$mask->pattern('****-****-****-****');

return $this->evaluate($mask, [
'mask' => app(TextInput\Mask::class),
]);
}
}
Solution:
Fix: ``` public function getValidationRules(): array { return ['required', new OrcidChecksum]; }...
Jump to solution
1 Reply
Solution
BuggerSee
BuggerSee16mo ago
Fix:
public function getValidationRules(): array
{
return ['required', new OrcidChecksum];
}
public function getValidationRules(): array
{
return ['required', new OrcidChecksum];
}
Want results from more Discord servers?
Add your server