1
|
|
|
<?php |
2
|
|
|
namespace Ajax\semantic\components; |
3
|
|
|
|
4
|
|
|
use Ajax\JsUtils; |
5
|
|
|
use Ajax\semantic\components\validation\FieldValidation; |
6
|
|
|
use Ajax\semantic\components\validation\Rule; |
7
|
|
|
/** |
8
|
|
|
* @author jc |
9
|
|
|
* @version 1.001 |
10
|
|
|
* Generates a JSON form validation string |
11
|
|
|
*/ |
12
|
|
|
class Form extends SimpleSemExtComponent { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
public function __construct(JsUtils $js=null) { |
18
|
|
|
parent::__construct($js); |
|
|
|
|
19
|
|
|
$this->uiName="form"; |
20
|
|
|
$this->params["fields"]=[]; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function addField($identifier){ |
24
|
|
|
$this->params["fields"][$identifier]=new FieldValidation($identifier); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function setInline($value){ |
|
|
|
|
28
|
|
|
return $this->setParam("inline", true); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function setOn($value){ |
32
|
|
|
return $this->setParam("on", $value); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $identifier |
39
|
|
|
* @param Rule|string $type |
40
|
|
|
* @param mixed $value |
41
|
|
|
* @param string|NULL $prompt |
42
|
|
|
*/ |
43
|
|
|
public function addFieldRule($identifier,$type,$prompt=NULL,$value=NULL){ |
44
|
|
|
if(isset($this->params["fields"][$identifier])===false){ |
45
|
|
|
$this->addField($identifier); |
46
|
|
|
} |
47
|
|
|
$this->params["fields"][$identifier]->addRule($type,$prompt,$value); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param FieldValidation $fieldValidation |
52
|
|
|
*/ |
53
|
|
|
public function addFieldValidation($fieldValidation){ |
54
|
|
|
$this->params["fields"][$fieldValidation->getIdentifier()]=$fieldValidation; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function setJs(JsUtils $js){ |
58
|
|
|
$this->js=$js; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getScript() { |
62
|
|
|
$allParams=$this->params; |
63
|
|
|
$this->jquery_code_for_compile=array (); |
64
|
|
|
$this->jquery_code_for_compile []="$( \"".$this->attachTo."\" ).{$this->uiName}(".$this->getParamsAsJSON($allParams).");"; |
65
|
|
|
$this->compileEvents(); |
66
|
|
|
return $this->compileJQueryCode(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function onValid($jsCode){ |
70
|
|
|
$this->addComponentEvent("onValid", $jsCode); |
71
|
|
|
} |
72
|
|
|
} |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):