1414use Ajax \semantic \html \collections \form \HtmlFormTextarea ;
1515use Ajax \semantic \html \collections \form \HtmlFormFields ;
1616use Ajax \semantic \html \collections \HtmlMessage ;
17+ use Ajax \semantic \html \elements \HtmlButton ;
1718
1819/**
1920 * @author jc
@@ -27,20 +28,21 @@ abstract protected function _getFieldIdentifier($prefix,$name="");
2728 abstract public function setValueFunction ($ index ,$ callback );
2829 abstract protected function _getFieldName ($ index );
2930 abstract protected function _getFieldCaption ($ index );
31+ abstract protected function _buttonAsSubmit (&$ button ,$ event ,$ url ,$ responseElement =NULL );
3032
3133 /**
3234 * @param HtmlFormField $element
3335 * @param array $attributes
3436 */
3537 protected function _applyAttributes ($ element ,&$ attributes ,$ index ){
36- $ this ->_addRules ($ element , $ attributes );
3738 if (isset ($ attributes ["callback " ])){
3839 $ callback =$ attributes ["callback " ];
3940 if (\is_callable ($ callback )){
4041 $ callback ($ element ,$ this ->_modelInstance ,$ index );
4142 unset($ attributes ["callback " ]);
4243 }
4344 }
45+ unset($ attributes ["rules " ]);
4446 $ element ->fromArray ($ attributes );
4547 }
4648
@@ -55,12 +57,19 @@ protected function _addRules($element,&$attributes){
5557 if (\is_array ($ rules )){
5658 $ element ->addRules ($ rules );
5759 }
58- else
60+ else {
5961 $ element ->addRule ($ rules );
60- unset($ attributes ["rules " ]);
62+ }
63+ unset($ attributes ["rules " ]);
6164 }
6265 }
6366
67+ protected function _prepareFormFields (&$ field ,$ name ,&$ attributes ){
68+ $ field ->setName ($ name );
69+ $ this ->_addRules ($ field , $ attributes );
70+ return $ field ;
71+ }
72+
6473 protected function _fieldAs ($ elementCallback ,$ index ,$ attributes =NULL ,$ prefix =null ){
6574 $ this ->setValueFunction ($ index ,function ($ value ) use ($ index ,&$ attributes ,$ elementCallback ,$ prefix ){
6675 $ caption =$ this ->_getFieldCaption ($ index );
@@ -145,10 +154,9 @@ public function fieldAsRadios($index,$elements=[],$attributes=NULL){
145154 }
146155
147156 public function fieldAsInput ($ index ,$ attributes =NULL ){
148- return $ this ->_fieldAs (function ($ id ,$ name ,$ value ,$ caption ){
157+ return $ this ->_fieldAs (function ($ id ,$ name ,$ value ,$ caption ) use ( $ attributes ) {
149158 $ input = new HtmlFormInput ($ id ,$ caption ,"text " ,$ value );
150- $ input ->setName ($ name );
151- return $ input ;
159+ return $ this ->_prepareFormFields ($ input , $ name , $ attributes );
152160 }, $ index ,$ attributes ,"input " );
153161 }
154162
@@ -192,4 +200,12 @@ public function fieldAsMessage($index,$attributes=NULL){
192200 return $ mess ;
193201 }, $ index ,$ attributes ,"message " );
194202 }
203+
204+ public function fieldAsSubmit ($ index ,$ cssStyle =NULL ,$ url =NULL ,$ responseElement =NULL ,$ attributes =NULL ){
205+ return $ this ->_fieldAs (function ($ id ,$ name ,$ value ,$ caption ) use ($ url ,$ responseElement ,$ cssStyle ){
206+ $ button =new HtmlButton ($ id ,$ value ,$ cssStyle );
207+ $ this ->_buttonAsSubmit ($ button ,"click " ,$ url ,$ responseElement );
208+ return $ button ;
209+ }, $ index ,$ attributes );
210+ }
195211}
0 commit comments