1 | <?php |
||
10 | class JavascriptValidator implements Arrayable |
||
11 | { |
||
12 | /** |
||
13 | * Registered validator instance. |
||
14 | * |
||
15 | * @var \Proengsoft\JsValidation\Javascript\ValidatorHandler |
||
16 | */ |
||
17 | protected $validator; |
||
18 | |||
19 | /** |
||
20 | * Selector used in javascript generation. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $selector; |
||
25 | |||
26 | /** |
||
27 | * View that renders Javascript. |
||
28 | * |
||
29 | * @var |
||
30 | */ |
||
31 | protected $view; |
||
32 | |||
33 | /** |
||
34 | * Enable or disable remote validations. |
||
35 | * |
||
36 | * @var bool |
||
37 | */ |
||
38 | protected $remote; |
||
39 | |||
40 | /** |
||
41 | * 'ignore' option for jQuery Validation Plugin. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $ignore; |
||
46 | |||
47 | /** |
||
48 | * @param ValidatorHandler $validator |
||
49 | * @param array $options |
||
50 | */ |
||
51 | 192 | public function __construct(ValidatorHandler $validator, $options = []) |
|
56 | |||
57 | /** |
||
58 | * Set default parameters. |
||
59 | * |
||
60 | * @param $options |
||
61 | */ |
||
62 | 192 | 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 | 48 | public function render($view = null, $selector = null) |
|
85 | |||
86 | /** |
||
87 | * Get the view data as an array. |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | 48 | public function toArray() |
|
95 | |||
96 | /** |
||
97 | * Get the string resulting of render default view. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 24 | public function __toString() |
|
102 | { |
||
103 | try { |
||
104 | 24 | return $this->render(); |
|
105 | 12 | } catch (Exception $exception) { |
|
106 | 12 | return trigger_error($exception->__toString(), E_USER_ERROR); |
|
107 | } |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Gets value from view data. |
||
112 | * |
||
113 | * @param $name |
||
114 | * |
||
115 | * @return string |
||
116 | * |
||
117 | * @throws PropertyNotFoundException |
||
118 | */ |
||
119 | 24 | public function __get($name) |
|
128 | |||
129 | /** |
||
130 | * Gets view data. |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | 120 | protected function getViewData() |
|
146 | |||
147 | /** |
||
148 | * Set the form selector to validate. |
||
149 | * |
||
150 | * @param string $selector |
||
151 | * |
||
152 | * @deprecated |
||
153 | */ |
||
154 | public function setSelector($selector) |
||
155 | { |
||
156 | $this->selector = $selector; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Set the form selector to validate. |
||
161 | * |
||
162 | * @param string $selector |
||
163 | * |
||
164 | * @return JavascriptValidator |
||
165 | */ |
||
166 | 48 | public function selector($selector) |
|
172 | |||
173 | /** |
||
174 | * Set the input selector to ignore for validation. |
||
175 | * |
||
176 | * @param string $ignore |
||
177 | * |
||
178 | * @return JavascriptValidator |
||
179 | */ |
||
180 | 12 | public function ignore($ignore) |
|
186 | |||
187 | /** |
||
188 | * Set the view to render Javascript Validations. |
||
189 | * |
||
190 | * @param \Illuminate\Contracts\View\View|string|null $view |
||
191 | * |
||
192 | * @return JavascriptValidator |
||
193 | */ |
||
194 | 48 | public function view($view) |
|
200 | |||
201 | /** |
||
202 | * Enables or disables remote validations. |
||
203 | * |
||
204 | * @param bool|null $enabled |
||
205 | * |
||
206 | * @return JavascriptValidator |
||
207 | */ |
||
208 | 12 | public function remote($enabled = true) |
|
214 | |||
215 | /** |
||
216 | * Validate Conditional Validations using Ajax in specified fields. |
||
217 | * |
||
218 | * @param string $attribute |
||
219 | * @param string|array $rules |
||
220 | * |
||
221 | * @return JavascriptValidator |
||
222 | */ |
||
223 | 12 | public function sometimes($attribute, $rules) |
|
229 | } |
||
230 |