Skip to content

Commit

Permalink
Fix external_link and html validation (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: RBF <[email protected]>
  • Loading branch information
Robin-Snow and RBF authored Sep 5, 2022
1 parent fa51b85 commit 0c74896
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Resources/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function (Select $field, NovaRequest $request, FormData $formData) {
Text::make(trans('laravel-nova-menu::menu.external_link'), 'external_link')
->help(trans('laravel-nova-menu::menu.must_start_with_http'))
->nullable()
->rules('max:191', 'required_without_all:internal_link,html', function ($attribute, $value, $fail) {
->rules('max:191', 'required_if:link_type,'.\Novius\LaravelNovaMenu\Models\MenuItem::TYPE_EXTERNAL_LINK, function ($attribute, $value, $fail) {
if (!empty($value) && !Validator::make([$attribute => $value], [$attribute => 'url'])->passes()) {
return $fail(trans('laravel-nova-menu::errors.bad_format_external_link'));
}
Expand All @@ -180,7 +180,7 @@ function (Text $field, NovaRequest $request, FormData $formData) {

Code::make(trans('laravel-nova-menu::menu.html'), 'html')
->help(trans('laravel-nova-menu::menu.help_code'))
->rules('required_without_all:internal_link,external_link', 'max:'.config('laravel-nova-menu.menu_item_html_max_size'))
->rules('required_if:link_type,'.\Novius\LaravelNovaMenu\Models\MenuItem::TYPE_HTML, 'max:'.config('laravel-nova-menu.menu_item_html_max_size'))
->hideFromDetail(function ($ressource, $fields) {
return empty($fields->html);
})
Expand Down

0 comments on commit 0c74896

Please sign in to comment.