File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed
com.woltlab.wcf/templates
wcfsetup/install/files/lib
system/form/builder/container/condition Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 2121 <button type =" button" class =" button" id =" { $container -> getPrefixedId ()} AddCondition" >
2222 { lang} wcf.condition.add{ /lang}
2323 </button >
24+
25+ { if $container -> isRequired () && $container -> isEmpty ()}
26+ <small class =" innerError" >{ lang} wcf.global.form.error.empty{ /lang} </small >
27+ { /if }
2428</section >
2529
2630{ include file= ' shared_formContainerDependencies' }
Original file line number Diff line number Diff line change @@ -160,11 +160,11 @@ public function createForm()
160160 ->fieldId ('type ' )
161161 ->values ([Trophy::TYPE_BADGE ])
162162 ),
163- // TODO make it required
164163 ConditionFormContainer::create ()
165164 ->label ('wcf.acp.trophy.conditions ' )
166165 ->description ('wcf.acp.trophy.conditions.description ' )
167166 ->conditionProvider (new UserConditionProvider ())
167+ ->required ()
168168 ->addDependency (
169169 NonEmptyFormFieldDependency::create ('awardAutomaticallyDependency ' )
170170 ->fieldId ('awardAutomatically ' )
Original file line number Diff line number Diff line change @@ -31,13 +31,24 @@ final class ConditionFormContainer extends FormContainer
3131 * @phpstan-ignore missingType.generics
3232 */
3333 protected AbstractConditionProvider $ conditionProvider ;
34+ private bool $ isRequired = false ;
3435
3536 public function __construct ()
3637 {
3738 parent ::__construct ();
3839 $ this ->label ("wcf.form.field.condition " );
3940 }
4041
42+ public function hasValidationErrors (): bool
43+ {
44+ if ($ this ->isRequired && $ this ->isEmpty ()) {
45+ return true ;
46+ }
47+
48+ return parent ::hasValidationErrors ();
49+ }
50+
51+
4152 #[\Override]
4253 protected static function getDefaultId (): string
4354 {
@@ -165,4 +176,21 @@ public function getConditionProviderClass(): string
165176
166177 return $ this ->conditionProvider ::class;
167178 }
179+
180+ public function required (bool $ isRequired = true ): self
181+ {
182+ $ this ->isRequired = $ isRequired ;
183+
184+ return $ this ;
185+ }
186+
187+ public function isRequired (): bool
188+ {
189+ return $ this ->isRequired ;
190+ }
191+
192+ public function isEmpty (): bool
193+ {
194+ return !$ this ->hasChildren ();
195+ }
168196}
You can’t perform that action at this time.
0 commit comments