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) |
|
67 | |||
68 | /** |
||
69 | * Render the specified view with validator data. |
||
70 | * |
||
71 | * @param \Illuminate\Contracts\View\View|string|null $view |
||
72 | * @param string|null $selector |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | 3 | public function render($view = null, $selector = null) |
|
84 | |||
85 | /** |
||
86 | * Get the view data as an array. |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | 3 | public function toArray() |
|
94 | |||
95 | /** |
||
96 | * Get the string resulting of render default view. |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | 1 | public function __toString() |
|
104 | |||
105 | /** |
||
106 | * Gets value from view data. |
||
107 | * |
||
108 | * @param $name |
||
109 | * |
||
110 | * @return string |
||
111 | * |
||
112 | * @throws PropertyNotFoundException |
||
113 | */ |
||
114 | 2 | public function __get($name) |
|
123 | |||
124 | /** |
||
125 | * Gets view data. |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | 8 | protected function getViewData() |
|
130 | { |
||
131 | 8 | $data = $this->validator->validationData($this->remote); |
|
132 | 8 | $data['selector'] = $this->selector; |
|
133 | |||
134 | 8 | if (! is_null($this->ignore)) { |
|
135 | 1 | $data['ignore'] = $this->ignore; |
|
136 | } |
||
137 | |||
138 | 8 | return $data; |
|
139 | } |
||
140 | |||
141 | /** |
||
142 | * Set the form selector to validate. |
||
143 | * |
||
144 | * @param string $selector |
||
145 | * |
||
146 | * @deprecated |
||
147 | */ |
||
148 | public function setSelector($selector) |
||
152 | |||
153 | /** |
||
154 | * Set the form selector to validate. |
||
155 | * |
||
156 | * @param string $selector |
||
157 | * |
||
158 | * @return JavascriptValidator |
||
159 | */ |
||
160 | 3 | public function selector($selector) |
|
166 | |||
167 | /** |
||
168 | * Set the input selector to ignore for validation. |
||
169 | * |
||
170 | * @param string $ignore |
||
171 | * |
||
172 | * @return JavascriptValidator |
||
173 | */ |
||
174 | 1 | public function ignore($ignore) |
|
180 | |||
181 | /** |
||
182 | * Set the view to render Javascript Validations. |
||
183 | * |
||
184 | * @param \Illuminate\Contracts\View\View|string|null $view |
||
185 | * |
||
186 | * @return JavascriptValidator |
||
187 | */ |
||
188 | 3 | public function view($view) |
|
194 | |||
195 | /** |
||
196 | * Enables or disables remote validations. |
||
197 | * |
||
198 | * @param bool|null $enabled |
||
199 | * |
||
200 | * @return JavascriptValidator |
||
201 | */ |
||
202 | 1 | public function remote($enabled = true) |
|
208 | |||
209 | /** |
||
210 | * Validate Conditional Validations using Ajax in specified fields. |
||
211 | * |
||
212 | * @param string|array $attribute |
||
213 | * @param string|array $rules |
||
214 | |||
215 | * @return JavascriptValidator |
||
216 | */ |
||
217 | public function sometimes($attribute, $rules) |
||
223 | } |
||
224 |