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 \Proengsoft\JsValidation\Javascript\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 | * @return void |
||
62 | */ |
||
63 | 192 | protected function setDefaults($options) |
|
64 | { |
||
65 | 192 | $this->selector = empty($options['selector']) ? 'form' : $options['selector']; |
|
66 | 192 | $this->view = empty($options['view']) ? 'jsvalidation::bootstrap' : $options['view']; |
|
67 | 192 | $this->remote = isset($options['remote']) ? $options['remote'] : true; |
|
68 | 192 | } |
|
69 | |||
70 | /** |
||
71 | * Render the specified view with validator data. |
||
72 | * |
||
73 | * @param null|\Illuminate\Contracts\View\View|string $view |
||
74 | * @param null|string $selector |
||
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() |
|
109 | |||
110 | /** |
||
111 | * Gets value from view data. |
||
112 | * |
||
113 | * @param $name |
||
114 | * @return string |
||
115 | * |
||
116 | * @throws \Proengsoft\JsValidation\Exceptions\PropertyNotFoundException |
||
117 | */ |
||
118 | 24 | public function __get($name) |
|
127 | |||
128 | /** |
||
129 | * Gets view data. |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | 120 | protected function getViewData() |
|
145 | |||
146 | /** |
||
147 | * Set the form selector to validate. |
||
148 | * |
||
149 | * @param string $selector |
||
150 | * @deprecated |
||
151 | */ |
||
152 | public function setSelector($selector) |
||
156 | |||
157 | /** |
||
158 | * Set the form selector to validate. |
||
159 | * |
||
160 | * @param string $selector |
||
161 | * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator |
||
162 | */ |
||
163 | 48 | public function selector($selector) |
|
169 | |||
170 | /** |
||
171 | * Set the input selector to ignore for validation. |
||
172 | * |
||
173 | * @param string $ignore |
||
174 | * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator |
||
175 | */ |
||
176 | 12 | public function ignore($ignore) |
|
182 | |||
183 | /** |
||
184 | * Set the view to render Javascript Validations. |
||
185 | * |
||
186 | * @param null|\Illuminate\Contracts\View\View|string $view |
||
187 | * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator |
||
188 | */ |
||
189 | 48 | public function view($view) |
|
195 | |||
196 | /** |
||
197 | * Enables or disables remote validations. |
||
198 | * |
||
199 | * @param null|bool $enabled |
||
200 | * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator |
||
201 | */ |
||
202 | 12 | public function remote($enabled = true) |
|
208 | |||
209 | /** |
||
210 | * Validate Conditional Validations using Ajax in specified fields. |
||
211 | * |
||
212 | * @param string $attribute |
||
213 | * @param string|array $rules |
||
214 | * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator |
||
215 | */ |
||
216 | 12 | public function sometimes($attribute, $rules) |
|
222 | } |
||
223 |