Skip to content

Commit

Permalink
Merge pull request #1175 from cultuurnet/PPF-491-make-website-require…
Browse files Browse the repository at this point in the history
…d-on-uitpas

PPF-491 Use dependsOn to make website required when switching to UiTPAS
  • Loading branch information
LucWollants authored Jun 4, 2024
2 parents 803307f + 499da8e commit 1541440
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/Nova/Resources/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Fields\FormData;
use Laravel\Nova\Fields\HasMany;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Select;
Expand Down Expand Up @@ -135,17 +136,23 @@ public function fields(NovaRequest $request): array

URL::make('Website')
->displayUsing(fn () => $this->website)
->required(fn () => $this->type === IntegrationType::UiTPAS->value)
->showOnIndex(false)
->rules(function () {
$rules = ['url:http,https', 'max:255'];

if ($this->type !== IntegrationType::UiTPAS->value) {
$rules[] = 'nullable';
->dependsOn(
['type'],
function (Text $field, NovaRequest $request, FormData $formData) {
$rules = ['url:http,https', 'max:255'];
$required = true;

if ($formData->string('type')->toString() !== IntegrationType::UiTPAS->value) {
$rules[] = 'nullable';
$required = false;
}

$field
->required($required)
->rules($rules);
}

return $rules;
}),
),

BelongsTo::make('Organization')
->withoutTrashed()
Expand Down

0 comments on commit 1541440

Please sign in to comment.