@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @author jc |
| 16 | 16 | * |
| 17 | 17 | */ |
| 18 | -trait FormTrait{ |
|
| 18 | +trait FormTrait { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @return HtmlForm |
@@ -24,26 +24,26 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | protected $_runnedParams=false; |
| 26 | 26 | |
| 27 | - protected function addCompoValidation(Form $compo,HtmlFormField $field){ |
|
| 27 | + protected function addCompoValidation(Form $compo, HtmlFormField $field) { |
|
| 28 | 28 | $validation=$field->getValidation(); |
| 29 | - if(isset($validation)){ |
|
| 29 | + if (isset($validation)) { |
|
| 30 | 30 | $validation->setIdentifier($field->getDataField()->getIdentifier()); |
| 31 | 31 | $compo->addFieldValidation($validation); |
| 32 | 32 | } |
| 33 | 33 | return $compo; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - protected function addExtraCompoValidation(Form $compo,FieldValidation $validation){ |
|
| 36 | + protected function addExtraCompoValidation(Form $compo, FieldValidation $validation) { |
|
| 37 | 37 | $compo->addFieldValidation($validation); |
| 38 | 38 | return $compo; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - protected function _runValidationParams(Form &$compo,JsUtils $js=NULL){ |
|
| 42 | - if(!$this->_runnedParams){ |
|
| 41 | + protected function _runValidationParams(Form &$compo, JsUtils $js=NULL) { |
|
| 42 | + if (!$this->_runnedParams) { |
|
| 43 | 43 | $form=$this->getForm(); |
| 44 | 44 | $params=$form->getValidationParams(); |
| 45 | - if(isset($params["_ajaxSubmit"])){ |
|
| 46 | - $compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"],$js); |
|
| 45 | + if (isset($params["_ajaxSubmit"])) { |
|
| 46 | + $compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"], $js); |
|
| 47 | 47 | $this->onSuccess($compilation); |
| 48 | 48 | $form->removeValidationParam("_ajaxSubmit"); |
| 49 | 49 | } |
@@ -54,16 +54,16 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - protected function _compileAjaxSubmit($ajaxSubmit,JsUtils $js=null){ |
|
| 57 | + protected function _compileAjaxSubmit($ajaxSubmit, JsUtils $js=null) { |
|
| 58 | 58 | $compilation=""; |
| 59 | - if(\is_array($ajaxSubmit)){ |
|
| 60 | - foreach ($ajaxSubmit as $ajaxSubmitItem){ |
|
| 59 | + if (\is_array($ajaxSubmit)) { |
|
| 60 | + foreach ($ajaxSubmit as $ajaxSubmitItem) { |
|
| 61 | 61 | $compilation.=$ajaxSubmitItem->compile($js); |
| 62 | 62 | } |
| 63 | - }elseif($ajaxSubmit instanceof AjaxCall){ |
|
| 63 | + }elseif ($ajaxSubmit instanceof AjaxCall) { |
|
| 64 | 64 | $compilation=$ajaxSubmit->compile($js); |
| 65 | 65 | } |
| 66 | - $compilation=str_ireplace("\"","%quote%", $compilation); |
|
| 66 | + $compilation=str_ireplace("\"", "%quote%", $compilation); |
|
| 67 | 67 | return $compilation; |
| 68 | 68 | } |
| 69 | 69 | |
@@ -76,14 +76,14 @@ discard block |
||
| 76 | 76 | return $this; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public function setAttached($value=true){ |
|
| 79 | + public function setAttached($value=true) { |
|
| 80 | 80 | $form=$this->getForm(); |
| 81 | - if($value) |
|
| 82 | - $form->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
| 81 | + if ($value) |
|
| 82 | + $form->addToPropertyCtrl("class", "attached", array("attached")); |
|
| 83 | 83 | return $form; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - public function addErrorMessage(){ |
|
| 86 | + public function addErrorMessage() { |
|
| 87 | 87 | return $this->getForm()->addContent((new HtmlMessage(""))->setError()); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -99,48 +99,48 @@ discard block |
||
| 99 | 99 | * @param array $parameters |
| 100 | 100 | * @return HtmlForm |
| 101 | 101 | */ |
| 102 | - public function submitOn($event,$identifierOrElement,$url,$responseElement,$parameters=NULL){ |
|
| 102 | + public function submitOn($event, $identifierOrElement, $url, $responseElement, $parameters=NULL) { |
|
| 103 | 103 | $form=$this->getForm(); |
| 104 | - if($identifierOrElement instanceof BaseHtml) |
|
| 104 | + if ($identifierOrElement instanceof BaseHtml) |
|
| 105 | 105 | $elem=$identifierOrElement; |
| 106 | 106 | else |
| 107 | 107 | $elem=$form->getElementById($identifierOrElement, $form->getContent()); |
| 108 | - if(isset($elem)){ |
|
| 109 | - $this->_buttonAsSubmit($elem, $event,$url,$responseElement,$parameters); |
|
| 108 | + if (isset($elem)) { |
|
| 109 | + $this->_buttonAsSubmit($elem, $event, $url, $responseElement, $parameters); |
|
| 110 | 110 | } |
| 111 | 111 | return $form; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - public function submitOnClick($identifier,$url,$responseElement,$parameters=NULL){ |
|
| 115 | - return $this->submitOn("click", $identifier, $url, $responseElement,$parameters); |
|
| 114 | + public function submitOnClick($identifier, $url, $responseElement, $parameters=NULL) { |
|
| 115 | + return $this->submitOn("click", $identifier, $url, $responseElement, $parameters); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){ |
|
| 119 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
| 120 | - return $this->_buttonAsSubmit($bt, "click",$url,$responseElement,$parameters); |
|
| 118 | + public function addSubmit($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) { |
|
| 119 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
| 120 | + return $this->_buttonAsSubmit($bt, "click", $url, $responseElement, $parameters); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - protected function _buttonAsSubmit(BaseHtml &$button,$event,$url,$responseElement=NULL,$parameters=NULL){ |
|
| 123 | + protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement=NULL, $parameters=NULL) { |
|
| 124 | 124 | $form=$this->getForm(); |
| 125 | - if(isset($url) && isset($responseElement)){ |
|
| 126 | - $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');",true,true); |
|
| 127 | - $this->setSubmitParams($url,$responseElement,$parameters); |
|
| 125 | + if (isset($url) && isset($responseElement)) { |
|
| 126 | + $button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');", true, true); |
|
| 127 | + $this->setSubmitParams($url, $responseElement, $parameters); |
|
| 128 | 128 | } |
| 129 | 129 | return $button; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - public function setSubmitParams($url,$responseElement=NULL,$parameters=NULL){ |
|
| 132 | + public function setSubmitParams($url, $responseElement=NULL, $parameters=NULL) { |
|
| 133 | 133 | $form=$this->getForm(); |
| 134 | - $params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url,"stopPropagation"=>true]; |
|
| 135 | - if(\is_array($parameters)){ |
|
| 136 | - $params=\array_merge($params,$parameters); |
|
| 134 | + $params=["form"=>$form->getIdentifier(), "responseElement"=>$responseElement, "url"=>$url, "stopPropagation"=>true]; |
|
| 135 | + if (\is_array($parameters)) { |
|
| 136 | + $params=\array_merge($params, $parameters); |
|
| 137 | 137 | } |
| 138 | 138 | $form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params)); |
| 139 | 139 | return $this; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - public function addReset($identifier,$value,$cssStyle=NULL){ |
|
| 143 | - $bt=$this->getForm()->addButton($identifier, $value,$cssStyle); |
|
| 142 | + public function addReset($identifier, $value, $cssStyle=NULL) { |
|
| 143 | + $bt=$this->getForm()->addButton($identifier, $value, $cssStyle); |
|
| 144 | 144 | $bt->setProperty("type", "reset"); |
| 145 | 145 | return $bt; |
| 146 | 146 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param string $jsCode |
| 151 | 151 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
| 152 | 152 | */ |
| 153 | - public function onValid($jsCode){ |
|
| 153 | + public function onValid($jsCode) { |
|
| 154 | 154 | $form=$this->getForm(); |
| 155 | 155 | $form->addValidationParam("onValid", "%function(){".$jsCode."}%"); |
| 156 | 156 | return $form; |
@@ -161,27 +161,27 @@ discard block |
||
| 161 | 161 | * @param string $jsCode can use event and fields parameters |
| 162 | 162 | * @return HtmlForm |
| 163 | 163 | */ |
| 164 | - public function onSuccess($jsCode){ |
|
| 164 | + public function onSuccess($jsCode) { |
|
| 165 | 165 | $form=$this->getForm(); |
| 166 | - $form->addValidationParam("onSuccess", $jsCode,"%function(event,fields){","}%"); |
|
| 166 | + $form->addValidationParam("onSuccess", $jsCode, "%function(event,fields){", "}%"); |
|
| 167 | 167 | return $form; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - public function addExtraFieldRules($fieldname,$rules){ |
|
| 170 | + public function addExtraFieldRules($fieldname, $rules) { |
|
| 171 | 171 | $form=$this->getForm(); |
| 172 | 172 | $fv=$form->getExtraFieldValidation($fieldname); |
| 173 | - foreach ($rules as $rule){ |
|
| 173 | + foreach ($rules as $rule) { |
|
| 174 | 174 | $fv->addRule($rule); |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - public function addExtraFieldRule($fieldname,$type,$prompt=NULL,$value=NULL){ |
|
| 178 | + public function addExtraFieldRule($fieldname, $type, $prompt=NULL, $value=NULL) { |
|
| 179 | 179 | $form=$this->getForm(); |
| 180 | 180 | $fv=$form->getExtraFieldValidation($fieldname); |
| 181 | - $fv->addRule($type,$prompt,$value); |
|
| 181 | + $fv->addRule($type, $prompt, $value); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - public function setOptional($fieldname,$optional=true){ |
|
| 184 | + public function setOptional($fieldname, $optional=true) { |
|
| 185 | 185 | $form=$this->getForm(); |
| 186 | 186 | $fv=$form->getExtraFieldValidation($fieldname); |
| 187 | 187 | $fv->setOptional($optional); |