File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -121,4 +121,28 @@ public function renderUnwrapped()
121121
122122 return (new HiddenElement ($ this ->getValueOfNameAttribute (), ['value ' => $ this ->getUncheckedValue ()])) . $ html ;
123123 }
124+
125+ /**
126+ * Validate the element using all registered validators
127+ *
128+ * @return $this
129+ */
130+ public function validate ()
131+ {
132+ $ this ->ensureAssembled ();
133+
134+ if (! $ this ->hasValue () || $ this ->getValue () !== $ this ->getCheckedValue ()) {
135+ if ($ this ->isRequired ()) {
136+ $ this ->setMessages ([$ this ->translate ('This field is required. ' )]);
137+ $ this ->valid = false ;
138+ } else {
139+ $ this ->valid = true ;
140+ }
141+ } else {
142+ $ this ->valid = $ this ->getValidators ()->isValid ($ this ->getValue ());
143+ $ this ->setMessages ($ this ->getValidators ()->getMessages ());
144+ }
145+
146+ return $ this ;
147+ }
124148}
You can’t perform that action at this time.
0 commit comments