-
Notifications
You must be signed in to change notification settings - Fork 356
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
Fix/attribute validation #1798
Fix/attribute validation #1798
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@wychoong Looks like there are a number of failing tests, will set to draft for the time being and when it's done mark it as ready and I'll take a look :) |
37f1549
to
6d19265
Compare
i added in fixes from #1788 as well |
Thanks @wychoong This seems to work well, my only thinking now is that the validation rules input doesn't feel very intuitive, it's very easy to type something in wrong and will break the edit screens see screenshots: Do we need validation on that field or do something like Statamic where it will suggest rules and add them like tags. 🤔 @glennjacobs What do you think? |
I think a validation on the rules can be done, but the rule builder/tags could be too much of effort |
Screen.Recording.2024-06-07.at.11.43.05.AM.mov->debounce()
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if (blank($value)) {
return;
}
$fails = [];
foreach (explode('|', $value) as $rule) {
try {
Validator::make(['test' => 'a'], ['test' => $rule])->validate();
} catch (\BadMethodCallException $e) {
$fails[] = $rule;
} catch (Throwable $e) {
//
} catch (Exception $e) {
//
}
}
if (filled($fails)) {
$fail('Invalid rules: ' . implode(', ', $fails));
}
},
])
->afterStateUpdated(function ($livewire, Forms\Components\TextInput $component) {
$livewire->validateOnly($component->getStatePath());
}) |
fixes #1712