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

Fix/attribute validation #1798

Merged
merged 8 commits into from
Jul 4, 2024
Merged

Conversation

wychoong
Copy link
Contributor

fixes #1712

Copy link

vercel bot commented May 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 4, 2024 1:14pm

@alecritson
Copy link
Collaborator

@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 :)

@alecritson alecritson marked this pull request as draft June 4, 2024 13:56
@wychoong wychoong marked this pull request as ready for review June 5, 2024 08:37
@wychoong
Copy link
Contributor Author

wychoong commented Jun 5, 2024

i added in fixes from #1788 as well

@alecritson
Copy link
Collaborator

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:

image image

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?

@wychoong
Copy link
Contributor Author

wychoong commented Jun 6, 2024

I think a validation on the rules can be done, but the rule builder/tags could be too much of effort

@wychoong
Copy link
Contributor Author

wychoong commented Jun 7, 2024

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());
                    })

@glennjacobs glennjacobs merged commit c3e43f3 into lunarphp:1.x Jul 4, 2024
22 checks passed
@wychoong wychoong deleted the fix/attribute-validation branch July 4, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attribute validation rules
3 participants