1 | <?php |
||
9 | class JavascriptValidator implements Arrayable |
||
10 | { |
||
11 | /** |
||
12 | * Registered validator instance. |
||
13 | * |
||
14 | * @var \Proengsoft\JsValidation\Javascript\ValidatorHandler |
||
15 | */ |
||
16 | protected $validator; |
||
17 | |||
18 | /** |
||
19 | * Selector used in javascript generation. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $selector; |
||
24 | |||
25 | /** |
||
26 | * View that renders Javascript. |
||
27 | * |
||
28 | * @var |
||
29 | */ |
||
30 | protected $view; |
||
31 | |||
32 | /** |
||
33 | * Enable or disable remote validations. |
||
34 | * |
||
35 | * @var bool |
||
36 | */ |
||
37 | protected $remote; |
||
38 | |||
39 | /** |
||
40 | * 'ignore' option for jQuery Validation Plugin. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $ignore; |
||
45 | |||
46 | /** |
||
47 | * @param ValidatorHandler $validator |
||
48 | * @param array $options |
||
49 | */ |
||
50 | 12 | public function __construct(ValidatorHandler $validator, $options = []) |
|
55 | |||
56 | /** |
||
57 | * Set default parameters |
||
58 | * |
||
59 | * @param $options |
||
60 | */ |
||
61 | 12 | protected function setDefaults($options) { |
|
68 | |||
69 | /** |
||
70 | * Render the specified view with validator data. |
||
71 | * |
||
72 | * @param \Illuminate\Contracts\View\View|string|null $view |
||
73 | * @param string|null $selector |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | 3 | public function render($view = null, $selector = null) |
|
85 | |||
86 | /** |
||
87 | * Get the view data as an array. |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | 3 | public function toArray() |
|
95 | |||
96 | /** |
||
97 | * Get the string resulting of render default view. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 1 | public function __toString() |
|
102 | { |
||
103 | 1 | return $this->render(); |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * Gets value from view data. |
||
108 | * |
||
109 | * @param $name |
||
110 | * |
||
111 | * @return string |
||
112 | * |
||
113 | * @throws PropertyNotFoundException |
||
114 | */ |
||
115 | 2 | public function __get($name) |
|
124 | |||
125 | /** |
||
126 | * Gets view data. |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | 8 | protected function getViewData() |
|
141 | |||
142 | /** |
||
143 | * Set the form selector to validate. |
||
144 | * |
||
145 | * @param string $selector |
||
146 | * |
||
147 | * @deprecated |
||
148 | */ |
||
149 | public function setSelector($selector) |
||
153 | |||
154 | /** |
||
155 | * Set the form selector to validate. |
||
156 | * |
||
157 | * @param string $selector |
||
158 | * |
||
159 | * @return JavascriptValidator |
||
160 | */ |
||
161 | 3 | public function selector($selector) |
|
167 | |||
168 | /** |
||
169 | * Set the input selector to ignore for validation. |
||
170 | * |
||
171 | * @param string $ignore |
||
172 | * |
||
173 | * @return JavascriptValidator |
||
174 | */ |
||
175 | 1 | public function ignore($ignore) |
|
181 | |||
182 | /** |
||
183 | * Set the view to render Javascript Validations. |
||
184 | * |
||
185 | * @param \Illuminate\Contracts\View\View|string|null $view |
||
186 | * |
||
187 | * @return JavascriptValidator |
||
188 | */ |
||
189 | 3 | public function view($view) |
|
195 | |||
196 | /** |
||
197 | * Enables or disables remote validations. |
||
198 | * |
||
199 | * @param bool|null $enabled |
||
200 | * |
||
201 | * @return JavascriptValidator |
||
202 | */ |
||
203 | 1 | public function remote($enabled=true) |
|
209 | } |
||
210 |