@@ -51,7 +51,7 @@ class Html {
5151 *
5252 * @return string
5353 */
54- public static function getTitle ($ default ) {
54+ public static function getTitle ($ default = '' ) {
5555 if (empty (self ::$ viewContext ->title )) {
5656 if (isset (self ::$ viewContext ->body ) && !empty (self ::$ viewContext ->body ->title )) {
5757 return htmlspecialchars (self ::$ viewContext ->body ->title );
@@ -686,6 +686,14 @@ public static function textArea($name, $value = '', $rows = null, $columns = nul
686686 $ htmlAttributes ['name ' ] = isset ($ htmlAttributes ['name ' ]) ? $ htmlAttributes ['name ' ] : $ nameString ;
687687 $ htmlAttributes ['id ' ] = isset ($ htmlAttributes ['id ' ]) ? $ htmlAttributes ['id ' ] : $ nameString ;
688688
689+ if (!isset ($ htmlAttributes ['required ' ])) {
690+ if (!empty ($ annotation = self ::$ viewContext ->getModelState ()->getAnnotation ($ name ))) {
691+ if (isset ($ annotation ->required )) {
692+ $ htmlAttributes ['required ' ] = 'required ' ;
693+ }
694+ }
695+ }
696+
689697 if (self ::getModelValue ($ name , $ modelValue ) === true ) {
690698 $ value = $ modelValue ;
691699 }
@@ -781,6 +789,14 @@ private static function input($name, $type = 'text', $value = null, $htmlAttribu
781789 $ htmlAttributes ['name ' ] = isset ($ htmlAttributes ['name ' ]) ? $ htmlAttributes ['name ' ] : $ nameString ;
782790 $ htmlAttributes ['id ' ] = isset ($ htmlAttributes ['id ' ]) ? $ htmlAttributes ['id ' ] : $ nameString ;
783791
792+ if (!isset ($ htmlAttributes ['required ' ])) {
793+ if (!empty ($ annotation = self ::$ viewContext ->getModelState ()->getAnnotation ($ name ))) {
794+ if (isset ($ annotation ->required )) {
795+ $ htmlAttributes ['required ' ] = 'required ' ;
796+ }
797+ }
798+ }
799+
784800 if ($ ignoreModelValue !== true && self ::getModelValue ($ name , $ modelValue ) === true ) {
785801 $ value = $ modelValue ;
786802 }
0 commit comments