Skip to content

Commit fda645f

Browse files
committed
fieldsAsElement + post params
1 parent fd30d0a commit fda645f

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

Ajax/common/traits/JsUtilsAjaxTrait.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,13 @@ public function postOnClick($element, $url, $params="{}", $responseElement="", $
412412
return $this->postOn("click", $element, $url, $params, $responseElement, $parameters);
413413
}
414414

415-
private function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) {
415+
private function _postForm($url, $form, $responseElement, $params=null,$validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) {
416416
$jsCallback=isset($jsCallback) ? $jsCallback : "";
417417
$retour=$this->_getAjaxUrl($url, $attr);
418418
$retour.="\nvar params=$('#".$form."').serialize();\n";
419+
if(isset($params)){
420+
$retour.="params+='&'+$.param(".$params.");\n";
421+
}
419422
$responseElement=$this->_getResponseElement($responseElement);
420423
$retour.="var self=this;\n";
421424
if($hasLoader===true){
@@ -440,13 +443,14 @@ private function _postForm($url, $form, $responseElement, $validation=false, $js
440443
* @param string $url The url of the request
441444
* @param string $form The form HTML id
442445
* @param string $responseElement selector of the HTML element displaying the answer
446+
* @param string $params
443447
* @param string $jsCallback javascript code to execute after the request
444448
* @param boolean $hasLoader true for showing ajax loader. default : true
445449
* @param string $jqueryDone the jquery function call on ajax data. default:html
446450
* @param string|callable $ajaxTransition
447451
*/
448-
public function postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) {
449-
return $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true);
452+
public function postForm($url, $form, $responseElement, $params=NULL,$validation=false, $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) {
453+
return $this->_postForm($url, $form, $responseElement, $params,$validation, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true);
450454
}
451455

452456
/**
@@ -455,14 +459,16 @@ public function postForm($url, $form, $responseElement, $validation=false, $jsCa
455459
* @param string $url The url of the request
456460
* @param string $form The form HTML id
457461
* @param string $responseElement selector of the HTML element displaying the answer
462+
* @param string $params
463+
* @param boolean $validation
458464
* @param string $jsCallback javascript code to execute after the request
459465
* @param string $attr the html attribute added to the request
460466
* @param boolean $hasLoader true for showing ajax loader. default : true
461467
* @param string $jqueryDone the jquery function call on ajax data. default:html
462468
* @param string|callable $ajaxTransition
463469
*/
464-
public function postFormDeferred($url, $form, $responseElement, $validation=false, $jsCallback=NULL,$attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) {
465-
return $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false);
470+
public function postFormDeferred($url, $form, $responseElement, $params=NULL,$validation=false, $jsCallback=NULL,$attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) {
471+
return $this->_postForm($url, $form, $responseElement, $params,$validation, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false);
466472
}
467473

468474
/**
@@ -480,13 +486,14 @@ public function postFormOn($event, $element, $url, $form, $responseElement="", $
480486
$stopPropagation=true;
481487
$validation=false;
482488
$jsCallback=null;
489+
$params=null;
483490
$attr="id";
484491
$hasLoader=true;
485492
$immediatly=true;
486493
$jqueryDone="html";
487494
$ajaxTransition=null;
488495
extract($parameters);
489-
return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly);
496+
return $this->_add_event($element, $this->_postForm($url, $form, $responseElement,$params, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly);
490497
}
491498

492499
/**

Ajax/semantic/html/collections/form/traits/FieldsTrait.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
use Ajax\semantic\html\collections\form\HtmlFormCheckbox;
1010
use Ajax\semantic\html\collections\form\HtmlFormRadio;
1111
use Ajax\semantic\html\collections\form\HtmlFormField;
12+
use Ajax\common\html\html5\HtmlTextarea;
13+
use Ajax\common\html\HtmlDoubleElement;
14+
use Ajax\semantic\html\collections\form\HtmlFormTextarea;
15+
use Ajax\semantic\html\base\HtmlSemDoubleElement;
1216

1317
/**
1418
* @author jc
@@ -66,7 +70,7 @@ public function addFieldRules($index,$rules){
6670
* @param string $label
6771
* @param string $value
6872
* @param boolean $multiple
69-
* @return \Ajax\common\html\HtmlDoubleElement
73+
* @return HtmlDoubleElement
7074
*/
7175
public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){
7276
return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple));
@@ -84,6 +88,18 @@ public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$plac
8488
return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder));
8589
}
8690

91+
/**
92+
* @param string $identifier
93+
* @param string $label
94+
* @param string $value
95+
* @param string $placeholder
96+
* @param int $rows
97+
* @return HtmlTextarea
98+
*/
99+
public function addTextarea($identifier, $label,$value=NULL,$placeholder=NULL,$rows=5){
100+
return $this->addItem(new HtmlFormTextarea($identifier,$label,$value,$placeholder,$rows));
101+
}
102+
87103
public function addPassword($identifier, $label=NULL){
88104
return $this->addItem(new HtmlFormInput($identifier,$label,"password","",""));
89105
}
@@ -99,4 +115,9 @@ public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){
99115
public function addRadio($identifier, $name,$label=NULL,$value=NULL){
100116
return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value));
101117
}
118+
119+
public function addElement($identifier,$content,$label,$tagName="div",$baseClass=""){
120+
$div=new HtmlSemDoubleElement($identifier,$tagName,$baseClass,$content);
121+
return $this->addItem(new HtmlFormField("field-".$identifier, $div,$label));
122+
}
102123
}

Ajax/semantic/widgets/base/FieldAsTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Ajax\common\html\BaseHtml;
2121
use Ajax\semantic\html\collections\form\HtmlFormField;
2222
use Ajax\semantic\html\collections\form\HtmlFormRadio;
23+
use Ajax\semantic\html\base\HtmlSemDoubleElement;
2324

2425
/**
2526
* trait used in Widget
@@ -185,6 +186,16 @@ public function fieldAsTextarea($index,$attributes=NULL){
185186
}, $index,$attributes,"textarea");
186187
}
187188

189+
public function fieldAsElement($index,$tagName="div",$baseClass="",$attributes=NULL){
190+
return $this->_fieldAs(function($id,$name,$value,$caption) use ($attributes,$tagName,$baseClass){
191+
$div=new HtmlSemDoubleElement($id,$tagName,$baseClass);
192+
$div->setContent(\htmlentities($value));
193+
$textarea=new HtmlFormField("field-".$id, $div,$caption);
194+
return $this->_prepareFormFields($textarea, $name, $attributes);
195+
}, $index,$attributes,"element");
196+
}
197+
198+
188199
public function fieldAsHidden($index,$attributes=NULL){
189200
if(!\is_array($attributes)){
190201
$attributes=[];

Ajax/service/AjaxCall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function compile(JsUtils $js=null) {
3737
$result.=$js->postDeferred($url, $responseElement, $params, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition);
3838
break;
3939
case "postForm":
40-
$result.=$js->postFormDeferred($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition);
40+
$result.=$js->postFormDeferred($url, $form, $responseElement, $params,$validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition);
4141
break;
4242
case "json":
4343
$result.=$js->jsonDeferred($url,$method,$params,$jsCallback);

0 commit comments

Comments
 (0)