49
49
</div >
50
50
<div class =" col-sm-9" >
51
51
{{-- 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' } }" >
53
59
<select
54
60
class =" form-control"
55
61
for =" {{ $field [' configurationNames' ][' page_id' ] } }"
56
- required
62
+ {{ $shouldShowPageLink ? ' required' : ' ' } }
57
63
>
58
64
@foreach ($field [' pages' ] as $page )
59
65
<option value =" {{ $page -> id } }"
@@ -66,13 +72,16 @@ class="form-control"
66
72
</div >
67
73
68
74
{{-- 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' } }" >
70
79
<input
71
80
type =" text"
72
81
class =" form-control"
73
82
placeholder =" {{ trans (' backpack::crud.internal_link_placeholder' , [' url' , url (config (' backpack.base.route_prefix' ). ' /page' )]) } }"
74
83
for =" {{ $field [' configurationNames' ][' link' ] } }"
75
- required
84
+ {{ $shouldShowInternalLink ? ' required' : ' ' } }
76
85
@if (isset ($entry ) )
77
86
@if ($entry -> {$field [' configurationNames' ][' type' ]} !== ' internal_link' && $entry -> {$field [' configurationNames' ][' type' ]} !== ' page_link' )
78
87
disabled =" disabled"
@@ -88,15 +97,18 @@ class="form-control"
88
97
</div >
89
98
90
99
{{-- 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' } }" >
92
104
<input
93
105
type =" url"
94
106
class =" form-control"
95
107
placeholder =" {{ trans (' backpack::crud.page_link_placeholder' ) } }"
96
108
for =" {{ $field [' configurationNames' ][' link' ] } }"
97
- required
109
+ {{ $shouldShowExternalLink ? ' required' : ' ' } }
98
110
@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' ]) )
100
112
disabled =" disabled"
101
113
@endif
102
114
@@ -152,9 +164,10 @@ function bpFieldInitPageOrLinkElement(element) {
152
164
values .forEach (value => {
153
165
let isSelected = value .classList .contains (select .value );
154
166
155
- // toggle visibility and disabled
167
+ // toggle visibility, disabled and required validation
156
168
value .classList .toggle (' d-none' , ! isSelected);
157
169
value .firstElementChild .toggleAttribute (' disabled' , ! isSelected);
170
+ value .firstElementChild .toggleAttribute (' required' , isSelected);
158
171
});
159
172
160
173
// updates hidden fields
0 commit comments