4949 </div >
5050 <div class =" col-sm-9" >
5151 {{-- page slug input --}}
52- <div class =" page_or_link_value page_link {{ (isset ($entry ) && $entry -> {$field [' configurationNames' ][' type' ]} === ' page_link' ) || (isset ($entry ) && ! $entry -> {$field [' configurationNames' ][' type' ]} && ! $field [' allows_null' ]) || (! isset ($entry ) && ! $field [' allows_null' ]) ? ' ' : ' d-none' } }" >
52+ @php
53+ $shouldShowPageLink = (isset ($entry ) && $entry -> {$field [' configurationNames' ][' type' ]} === ' page_link' ) ||
54+ (isset ($entry ) && ! $entry -> {$field [' configurationNames' ][' type' ]} && ! $field [' allows_null' ]) ||
55+ (! isset ($entry ) && ! $field [' allows_null' ]);
56+
57+ @endphp
58+ <div class =" page_or_link_value page_link {{ $shouldShowPageLink ? ' ' : ' d-none' } }" >
5359 <select
5460 class =" form-control"
5561 for =" {{ $field [' configurationNames' ][' page_id' ] } }"
56- required
62+ {{ $shouldShowPageLink ? ' required' : ' ' } }
5763 >
5864 @foreach ($field [' pages' ] as $page )
5965 <option value =" {{ $page -> id } }"
@@ -66,13 +72,16 @@ class="form-control"
6672 </div >
6773
6874 {{-- internal link input --}}
69- <div class =" page_or_link_value internal_link {{ isset ($entry ) && $entry -> {$field [' configurationNames' ][' type' ]} === ' internal_link' ? ' ' : ' d-none' } }" >
75+ @php
76+ $shouldShowInternalLink = isset ($entry ) && $entry -> {$field [' configurationNames' ][' type' ]} === ' internal_link' ;
77+ @endphp
78+ <div class =" page_or_link_value internal_link {{ $shouldShowInternalLink ? ' ' : ' d-none' } }" >
7079 <input
7180 type =" text"
7281 class =" form-control"
7382 placeholder =" {{ trans (' backpack::crud.internal_link_placeholder' , [' url' , url (config (' backpack.base.route_prefix' ). ' /page' )]) } }"
7483 for =" {{ $field [' configurationNames' ][' link' ] } }"
75- required
84+ {{ $shouldShowInternalLink ? ' required' : ' ' } }
7685 @if (isset ($entry ) )
7786 @if ($entry -> {$field [' configurationNames' ][' type' ]} !== ' internal_link' && $entry -> {$field [' configurationNames' ][' type' ]} !== ' page_link' )
7887 disabled =" disabled"
@@ -88,15 +97,18 @@ class="form-control"
8897 </div >
8998
9099 {{-- external link input --}}
91- <div class =" page_or_link_value external_link {{ isset ($entry ) && $entry -> {$field [' configurationNames' ][' type' ]} === ' external_link' ? ' ' : ' d-none' } }" >
100+ @php
101+ $shouldShowExternalLink = isset ($entry ) && $entry -> {$field [' configurationNames' ][' type' ]} === ' external_link' ;
102+ @endphp
103+ <div class =" page_or_link_value external_link {{ $shouldShowExternalLink ? ' ' : ' d-none' } }" >
92104 <input
93105 type =" url"
94106 class =" form-control"
95107 placeholder =" {{ trans (' backpack::crud.page_link_placeholder' ) } }"
96108 for =" {{ $field [' configurationNames' ][' link' ] } }"
97- required
109+ {{ $shouldShowExternalLink ? ' required' : ' ' } }
98110 @if (isset ($entry ) )
99- @if ($entry -> {$field [' configurationNames' ][' type' ]} !== ' external_link' && $entry -> { $field [ ' configurationNames ' ][ ' type ' ]} !== ' page_link' )
111+ @if (! in_array ( $entry -> {$field [' configurationNames' ][' type' ]}, [ ' external_link' , ' page_link' ]) )
100112 disabled =" disabled"
101113 @endif
102114
@@ -152,9 +164,10 @@ function bpFieldInitPageOrLinkElement(element) {
152164 values .forEach (value => {
153165 let isSelected = value .classList .contains (select .value );
154166
155- // toggle visibility and disabled
167+ // toggle visibility, disabled and required validation
156168 value .classList .toggle (' d-none' , ! isSelected);
157169 value .firstElementChild .toggleAttribute (' disabled' , ! isSelected);
170+ value .firstElementChild .toggleAttribute (' required' , isSelected);
158171 });
159172
160173 // updates hidden fields
0 commit comments