parsley-rails 2.6.2.0 → 2.7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/parsley-rails/version.rb +1 -1
- data/update.sh +11 -0
- data/vendor/assets/javascripts/parsley.i18n.sk.extra.js +13 -0
- data/vendor/assets/javascripts/parsley.i18n.sk.js +29 -0
- data/vendor/assets/javascripts/parsley.i18n.sr.extra.js +14 -0
- data/vendor/assets/javascripts/parsley.i18n.sr.js +29 -0
- data/vendor/assets/javascripts/parsley.js +297 -238
- data/vendor/assets/javascripts/parsley.js.map +1 -0
- data/vendor/assets/javascripts/parsley.min.js +4 -4
- data/vendor/assets/javascripts/parsley.min.js.map +1 -0
- data/vendor/assets/javascripts/parsley.validator.comparison.js +42 -0
- data/vendor/assets/javascripts/parsley.validator.dateiso.js +8 -0
- data/vendor/assets/javascripts/parsley.validator.luhn.js +32 -0
- data/vendor/assets/javascripts/parsley.validator.notequalto.js +13 -0
- data/vendor/assets/javascripts/parsley.validator.words.js +31 -0
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '06923dad38a181bc6d0ffe1934efe17577d7782e'
|
4
|
+
data.tar.gz: 1744e8262e18c968351cfc4104a3f130b87d04f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7204ceefc835e8445859fdf09ea72944854e611885da4ff05181c63f5a0b9a2df8ce7841ea44011bba80961b1591afb945a146779d4528b627bea5627ee594cf
|
7
|
+
data.tar.gz: c29694f882374a1157aeda544ea4e4dfec2666edab0514aea2da4f63e6049b6c8cd9bab5bbf00351a9ce05c69643d7ac426d70feea3f8c6e880b3ded73897c1c
|
data/README.md
CHANGED
@@ -22,7 +22,6 @@ Add the following to your `app/assets/javascripts/application.js`:
|
|
22
22
|
|
23
23
|
To use a different i18n, add this right after:
|
24
24
|
|
25
|
-
//= require parsley.remote
|
26
25
|
//= require parsley.i18n.fr
|
27
26
|
|
28
27
|
Finally, if you want to use the default CSS, add the following to your
|
@@ -54,3 +53,8 @@ is a patch level of the gem itself.
|
|
54
53
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
54
|
4. Push to the branch (`git push origin my-new-feature`)
|
56
55
|
5. Create new Pull Request
|
56
|
+
Note that there's a script (./update.sh 2.6.5) for automatic update from the
|
57
|
+
official distribution. Unfortunately the files in the "extras" are not part of
|
58
|
+
the distribution and thus are not transpiled. And since I'm too lazy to
|
59
|
+
reliably script it, it's necessary to modify some of the files (`comparison.js`
|
60
|
+
as of now) and remove the offending lines.
|
data/update.sh
CHANGED
@@ -20,10 +20,21 @@ wget -O $FILE_NAME $RELEASE_URL
|
|
20
20
|
mkdir $EXTRACT_DIRECTORY
|
21
21
|
tar xfz $FILE_NAME -C $EXTRACT_DIRECTORY
|
22
22
|
|
23
|
+
# Copy the base distribution
|
23
24
|
cp "$RELEASE_PATH/dist/parsley.js" $VENDOR_JS_PATH
|
25
|
+
cp "$RELEASE_PATH/dist/parsley.js.map" $VENDOR_JS_PATH
|
24
26
|
cp "$RELEASE_PATH/dist/parsley.min.js" $VENDOR_JS_PATH
|
27
|
+
cp "$RELEASE_PATH/dist/parsley.min.js.map" $VENDOR_JS_PATH
|
25
28
|
cp "$RELEASE_PATH/src/parsley.css" $VENDOR_CSS_PATH
|
26
29
|
|
30
|
+
# Copy extras
|
31
|
+
cp "$RELEASE_PATH/src/extra/validator/comparison.js" "$VENDOR_JS_PATH/parsley.validator.comparison.js"
|
32
|
+
cp "$RELEASE_PATH/src/extra/validator/dateiso.js" "$VENDOR_JS_PATH/parsley.validator.dateiso.js"
|
33
|
+
cp "$RELEASE_PATH/src/extra/validator/luhn.js" "$VENDOR_JS_PATH/parsley.validator.luhn.js"
|
34
|
+
cp "$RELEASE_PATH/src/extra/validator/notequalto.js" "$VENDOR_JS_PATH/parsley.validator.notequalto.js"
|
35
|
+
cp "$RELEASE_PATH/src/extra/validator/words.js" "$VENDOR_JS_PATH/parsley.validator.words.js"
|
36
|
+
|
37
|
+
# Copy the i18n files
|
27
38
|
for file in "$RELEASE_PATH/dist/i18n/"*; do
|
28
39
|
base_name=$(basename "$file")
|
29
40
|
final_name="parsley.i18n.$(echo $base_name)"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// Validation errors messages for Parsley
|
2
|
+
// Load this after Parsley
|
3
|
+
|
4
|
+
Parsley.addMessages('sk', {
|
5
|
+
dateiso: "Prosím zadajte dátum vo formáte RRRR-MM-DD.",
|
6
|
+
minwords: "Prosím zadajte hodnotu dlhú %s slov a viacej.",
|
7
|
+
maxwords: "Prosím zadajte hodnotu kratšiu ako %s slov.",
|
8
|
+
words: "Prosím zadajte hodnotu medzi %s a %s slov.",
|
9
|
+
gt: "Táto hodnota musí byť väčšia.",
|
10
|
+
gte: "Táto hodnota musí byť väčšia alebo rovná.",
|
11
|
+
lt: "Táto hodnota musí byť menšia.",
|
12
|
+
lte: "Táto hodnota musí byť menšia alebo rovná."
|
13
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
// Validation errors messages for Parsley
|
2
|
+
// Load this after Parsley
|
3
|
+
|
4
|
+
Parsley.addMessages('sk', {
|
5
|
+
defaultMessage: "Prosím zadajte správnu hodnotu.",
|
6
|
+
type: {
|
7
|
+
email: "Prosím zadajte správnu emailovú adresu.",
|
8
|
+
url: "Prosím zadajte platnú URL adresu.",
|
9
|
+
number: "Toto pole môže obsahovať len čísla",
|
10
|
+
integer: "Toto pole môže obsahovať len celé čísla",
|
11
|
+
digits: "Toto pole môže obsahovať len kladné celé čísla.",
|
12
|
+
alphanum: "Toto pole môže obsahovať len alfanumerické znaky."
|
13
|
+
},
|
14
|
+
notblank: "Toto pole nesmie byť prázdne.",
|
15
|
+
required: "Toto pole je povinné.",
|
16
|
+
pattern: "Toto pole je je neplatné.",
|
17
|
+
min: "Prosím zadajte hodnotu väčšiu alebo rovnú %s.",
|
18
|
+
max: "Prosím zadajte hodnotu menšiu alebo rovnú %s.",
|
19
|
+
range: "Prosím zadajte hodnotu v rozmedzí %s a %s",
|
20
|
+
minlength: "Prosím zadajte hodnotu dlhú %s znakov a viacej.",
|
21
|
+
maxlength: "Prosím zadajte hodnotu kratšiu ako %s znakov.",
|
22
|
+
length: "Prosím zadajte hodnotu medzi %s a %s znakov.",
|
23
|
+
mincheck: "Je nutné vybrať minimálne %s z možností.",
|
24
|
+
maxcheck: "Je nutné vybrať maximálne %s z možností.",
|
25
|
+
check: "Je nutné vybrať od %s do %s z možností.",
|
26
|
+
equalto: "Prosím zadajte rovnakú hodnotu."
|
27
|
+
});
|
28
|
+
|
29
|
+
Parsley.setLocale('sk');
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// Extra validation errors messages for Parsley
|
2
|
+
// Load this after Parsley
|
3
|
+
|
4
|
+
Parsley.addMessages('sr', {
|
5
|
+
dateiso: "Unesite validan datum u formatu YYYY-MM-DD.",
|
6
|
+
minwords: "Potrebno je da unesete %s ili više reči.",
|
7
|
+
maxwords: "Moguće je uneti maksimalno %s reči.",
|
8
|
+
words: "Potrebno je da unesete između %s i %s reči.",
|
9
|
+
gt: "Ova vrednost mora da bude veća.",
|
10
|
+
gte: "Ova vrednost mora da bude veća ili jednaka.",
|
11
|
+
lt: "Ova vrednost mora da bude manja.",
|
12
|
+
lte: "Ova vrednost mora da bude manja ili jednaka.",
|
13
|
+
notequalto: "Sadržaj ovog polja mora biti različit."
|
14
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
// Validation errors messages for Parsley
|
2
|
+
// Load this after Parsley
|
3
|
+
|
4
|
+
Parsley.addMessages('sr', {
|
5
|
+
defaultMessage: "Uneta vrednost nije validna.",
|
6
|
+
type: {
|
7
|
+
email: "Unesite pravilnu email adresu.",
|
8
|
+
url: "Unesite pravilnu url adresu.",
|
9
|
+
number: "Unesite numeričku vrednost.",
|
10
|
+
integer: "Unesite ceo broj bez decimala.",
|
11
|
+
digits: "Unesite samo brojeve.",
|
12
|
+
alphanum: "Unesite samo alfanumeričke znake (slova i brojeve)."
|
13
|
+
},
|
14
|
+
notblank: "Ovo polje ne sme biti prazno.",
|
15
|
+
required: "Ovo polje je obavezno.",
|
16
|
+
pattern: "Uneta vrednost nije validna.",
|
17
|
+
min: "Vrednost mora biti veća ili jednaka %s.",
|
18
|
+
max: "Vrednost mora biti manja ili jednaka %s.",
|
19
|
+
range: "Vrednost mora biti između %s i %s.",
|
20
|
+
minlength: "Unos je prekratak. Mora imati najmanje %s znakova.",
|
21
|
+
maxlength: "Unos je predug. Može imati najviše %s znakova.",
|
22
|
+
length: "Dužina unosa je pogrešna. Broj znakova mora biti između %s i %s.",
|
23
|
+
mincheck: "Morate izabrati minimalno %s opcija.",
|
24
|
+
maxcheck: "Možete izabrati najviše %s opcija.",
|
25
|
+
check: "Broj izabranih opcija mora biti između %s i %s.",
|
26
|
+
equalto: "Unos mora biti jednak."
|
27
|
+
});
|
28
|
+
|
29
|
+
Parsley.setLocale('sr');
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* Parsley.js
|
3
|
-
* Version 2.
|
3
|
+
* Version 2.7.0 - built Wed, Mar 1st 2017, 3:53 pm
|
4
4
|
* http://parsleyjs.org
|
5
5
|
* Guillaume Potier - <guillaume@wisembly.com>
|
6
6
|
* Marc-Andre Lafortune - <petroselinum@marc-andre.ca>
|
@@ -12,6 +12,8 @@
|
|
12
12
|
//
|
13
13
|
var _slice = Array.prototype.slice;
|
14
14
|
|
15
|
+
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
|
16
|
+
|
15
17
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
16
18
|
|
17
19
|
(function (global, factory) {
|
@@ -22,7 +24,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
22
24
|
var globalID = 1;
|
23
25
|
var pastWarnings = {};
|
24
26
|
|
25
|
-
var
|
27
|
+
var Utils__Utils = {
|
26
28
|
// Parsley DOM-API
|
27
29
|
// returns object from dom attributes and values
|
28
30
|
attr: function attr($element, namespace, obj) {
|
@@ -109,6 +111,70 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
109
111
|
return string.replace(/^\s+|\s+$/g, '');
|
110
112
|
},
|
111
113
|
|
114
|
+
parse: {
|
115
|
+
date: function date(string) {
|
116
|
+
var parsed = string.match(/^(\d{4,})-(\d\d)-(\d\d)$/);
|
117
|
+
if (!parsed) return null;
|
118
|
+
|
119
|
+
var _parsed$map = parsed.map(function (x) {
|
120
|
+
return parseInt(x, 10);
|
121
|
+
});
|
122
|
+
|
123
|
+
var _parsed$map2 = _slicedToArray(_parsed$map, 4);
|
124
|
+
|
125
|
+
var _ = _parsed$map2[0];
|
126
|
+
var year = _parsed$map2[1];
|
127
|
+
var month = _parsed$map2[2];
|
128
|
+
var day = _parsed$map2[3];
|
129
|
+
|
130
|
+
var date = new Date(year, month - 1, day);
|
131
|
+
if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) return null;
|
132
|
+
return date;
|
133
|
+
},
|
134
|
+
string: function string(_string) {
|
135
|
+
return _string;
|
136
|
+
},
|
137
|
+
integer: function integer(string) {
|
138
|
+
if (isNaN(string)) return null;
|
139
|
+
return parseInt(string, 10);
|
140
|
+
},
|
141
|
+
number: function number(string) {
|
142
|
+
if (isNaN(string)) throw null;
|
143
|
+
return parseFloat(string);
|
144
|
+
},
|
145
|
+
'boolean': function _boolean(string) {
|
146
|
+
return !/^\s*false\s*$/i.test(string);
|
147
|
+
},
|
148
|
+
object: function object(string) {
|
149
|
+
return Utils__Utils.deserializeValue(string);
|
150
|
+
},
|
151
|
+
regexp: function regexp(_regexp) {
|
152
|
+
var flags = '';
|
153
|
+
|
154
|
+
// Test if RegExp is literal, if not, nothing to be done, otherwise, we need to isolate flags and pattern
|
155
|
+
if (/^\/.*\/(?:[gimy]*)$/.test(_regexp)) {
|
156
|
+
// Replace the regexp literal string with the first match group: ([gimy]*)
|
157
|
+
// If no flag is present, this will be a blank string
|
158
|
+
flags = _regexp.replace(/.*\/([gimy]*)$/, '$1');
|
159
|
+
// Again, replace the regexp literal string with the first match group:
|
160
|
+
// everything excluding the opening and closing slashes and the flags
|
161
|
+
_regexp = _regexp.replace(new RegExp('^/(.*?)/' + flags + '$'), '$1');
|
162
|
+
} else {
|
163
|
+
// Anchor regexp:
|
164
|
+
_regexp = '^' + _regexp + '$';
|
165
|
+
}
|
166
|
+
return new RegExp(_regexp, flags);
|
167
|
+
}
|
168
|
+
},
|
169
|
+
|
170
|
+
parseRequirement: function parseRequirement(requirementType, string) {
|
171
|
+
var converter = this.parse[requirementType || 'string'];
|
172
|
+
if (!converter) throw 'Unknown requirement specification: "' + requirementType + '"';
|
173
|
+
var converted = converter(string);
|
174
|
+
if (converted === null) throw 'Requirement is not a ' + requirementType + ': "' + string + '"';
|
175
|
+
return converted;
|
176
|
+
},
|
177
|
+
|
112
178
|
namespaceEvents: function namespaceEvents(events, namespace) {
|
113
179
|
events = this.trimString(events || '').split(/\s+/);
|
114
180
|
if (!events[0]) return '';
|
@@ -152,14 +218,14 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
152
218
|
_SubmitSelector: 'input[type="submit"], button:submit'
|
153
219
|
};
|
154
220
|
|
155
|
-
var
|
221
|
+
var Utils__default = Utils__Utils;
|
156
222
|
|
157
223
|
// All these options could be overriden and specified directly in DOM using
|
158
224
|
// `data-parsley-` default DOM-API
|
159
225
|
// eg: `inputs` can be set in DOM using `data-parsley-inputs="input, textarea"`
|
160
226
|
// eg: `data-parsley-stop-on-first-failing-constraint="false"`
|
161
227
|
|
162
|
-
var
|
228
|
+
var Defaults = {
|
163
229
|
// ### General
|
164
230
|
|
165
231
|
// Default data-namespace for DOM API
|
@@ -206,11 +272,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
206
272
|
|
207
273
|
// Return the `$element` that will receive these above success or error classes
|
208
274
|
// Could also be (and given directly from DOM) a valid selector like `'#div'`
|
209
|
-
classHandler: function classHandler(
|
275
|
+
classHandler: function classHandler(Field) {},
|
210
276
|
|
211
277
|
// Return the `$element` where errors will be appended
|
212
278
|
// Could also be (and given directly from DOM) a valid selector like `'#div'`
|
213
|
-
errorsContainer: function errorsContainer(
|
279
|
+
errorsContainer: function errorsContainer(Field) {},
|
214
280
|
|
215
281
|
// ul elem that would receive errors' list
|
216
282
|
errorsWrapper: '<ul class="parsley-errors-list"></ul>',
|
@@ -219,11 +285,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
219
285
|
errorTemplate: '<li></li>'
|
220
286
|
};
|
221
287
|
|
222
|
-
var
|
223
|
-
this.__id__ =
|
288
|
+
var Base = function Base() {
|
289
|
+
this.__id__ = Utils__default.generateID();
|
224
290
|
};
|
225
291
|
|
226
|
-
|
292
|
+
Base.prototype = {
|
227
293
|
asyncSupport: true, // Deprecated
|
228
294
|
|
229
295
|
_pipeAccordingToValidationResult: function _pipeAccordingToValidationResult() {
|
@@ -238,14 +304,14 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
238
304
|
},
|
239
305
|
|
240
306
|
actualizeOptions: function actualizeOptions() {
|
241
|
-
|
307
|
+
Utils__default.attr(this.$element, this.options.namespace, this.domOptions);
|
242
308
|
if (this.parent && this.parent.actualizeOptions) this.parent.actualizeOptions();
|
243
309
|
return this;
|
244
310
|
},
|
245
311
|
|
246
312
|
_resetOptions: function _resetOptions(initOptions) {
|
247
|
-
this.domOptions =
|
248
|
-
this.options =
|
313
|
+
this.domOptions = Utils__default.objectCreate(this.parent.options);
|
314
|
+
this.options = Utils__default.objectCreate(this.domOptions);
|
249
315
|
// Shallow copy of ownProperties of initOptions:
|
250
316
|
for (var i in initOptions) {
|
251
317
|
if (initOptions.hasOwnProperty(i)) this.options[i] = initOptions[i];
|
@@ -310,41 +376,8 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
310
376
|
return true;
|
311
377
|
},
|
312
378
|
|
313
|
-
// Reset UI
|
314
|
-
reset: function reset() {
|
315
|
-
// Field case: just emit a reset event for UI
|
316
|
-
if ('ParsleyForm' !== this.__class__) {
|
317
|
-
this._resetUI();
|
318
|
-
return this._trigger('reset');
|
319
|
-
}
|
320
|
-
|
321
|
-
// Form case: emit a reset event for each field
|
322
|
-
for (var i = 0; i < this.fields.length; i++) this.fields[i].reset();
|
323
|
-
|
324
|
-
this._trigger('reset');
|
325
|
-
},
|
326
|
-
|
327
|
-
// Destroy Parsley instance (+ UI)
|
328
|
-
destroy: function destroy() {
|
329
|
-
// Field case: emit destroy event to clean UI and then destroy stored instance
|
330
|
-
this._destroyUI();
|
331
|
-
if ('ParsleyForm' !== this.__class__) {
|
332
|
-
this.$element.removeData('Parsley');
|
333
|
-
this.$element.removeData('ParsleyFieldMultiple');
|
334
|
-
this._trigger('destroy');
|
335
|
-
|
336
|
-
return;
|
337
|
-
}
|
338
|
-
|
339
|
-
// Form case: destroy all its fields and then destroy stored instance
|
340
|
-
for (var i = 0; i < this.fields.length; i++) this.fields[i].destroy();
|
341
|
-
|
342
|
-
this.$element.removeData('Parsley');
|
343
|
-
this._trigger('destroy');
|
344
|
-
},
|
345
|
-
|
346
379
|
asyncIsValid: function asyncIsValid(group, force) {
|
347
|
-
|
380
|
+
Utils__default.warnOnce("asyncIsValid is deprecated; please use whenValid instead");
|
348
381
|
return this.whenValid({ group: group, force: force });
|
349
382
|
},
|
350
383
|
|
@@ -353,73 +386,24 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
353
386
|
}
|
354
387
|
};
|
355
388
|
|
356
|
-
var requirementConverters = {
|
357
|
-
string: function string(_string) {
|
358
|
-
return _string;
|
359
|
-
},
|
360
|
-
integer: function integer(string) {
|
361
|
-
if (isNaN(string)) throw 'Requirement is not an integer: "' + string + '"';
|
362
|
-
return parseInt(string, 10);
|
363
|
-
},
|
364
|
-
number: function number(string) {
|
365
|
-
if (isNaN(string)) throw 'Requirement is not a number: "' + string + '"';
|
366
|
-
return parseFloat(string);
|
367
|
-
},
|
368
|
-
reference: function reference(string) {
|
369
|
-
// Unused for now
|
370
|
-
var result = $(string);
|
371
|
-
if (result.length === 0) throw 'No such reference: "' + string + '"';
|
372
|
-
return result;
|
373
|
-
},
|
374
|
-
boolean: function boolean(string) {
|
375
|
-
return string !== 'false';
|
376
|
-
},
|
377
|
-
object: function object(string) {
|
378
|
-
return ParsleyUtils__default.deserializeValue(string);
|
379
|
-
},
|
380
|
-
regexp: function regexp(_regexp) {
|
381
|
-
var flags = '';
|
382
|
-
|
383
|
-
// Test if RegExp is literal, if not, nothing to be done, otherwise, we need to isolate flags and pattern
|
384
|
-
if (/^\/.*\/(?:[gimy]*)$/.test(_regexp)) {
|
385
|
-
// Replace the regexp literal string with the first match group: ([gimy]*)
|
386
|
-
// If no flag is present, this will be a blank string
|
387
|
-
flags = _regexp.replace(/.*\/([gimy]*)$/, '$1');
|
388
|
-
// Again, replace the regexp literal string with the first match group:
|
389
|
-
// everything excluding the opening and closing slashes and the flags
|
390
|
-
_regexp = _regexp.replace(new RegExp('^/(.*?)/' + flags + '$'), '$1');
|
391
|
-
} else {
|
392
|
-
// Anchor regexp:
|
393
|
-
_regexp = '^' + _regexp + '$';
|
394
|
-
}
|
395
|
-
return new RegExp(_regexp, flags);
|
396
|
-
}
|
397
|
-
};
|
398
|
-
|
399
389
|
var convertArrayRequirement = function convertArrayRequirement(string, length) {
|
400
390
|
var m = string.match(/^\s*\[(.*)\]\s*$/);
|
401
391
|
if (!m) throw 'Requirement is not an array: "' + string + '"';
|
402
|
-
var values = m[1].split(',').map(
|
392
|
+
var values = m[1].split(',').map(Utils__default.trimString);
|
403
393
|
if (values.length !== length) throw 'Requirement has ' + values.length + ' values when ' + length + ' are needed';
|
404
394
|
return values;
|
405
395
|
};
|
406
396
|
|
407
|
-
var convertRequirement = function convertRequirement(requirementType, string) {
|
408
|
-
var converter = requirementConverters[requirementType || 'string'];
|
409
|
-
if (!converter) throw 'Unknown requirement specification: "' + requirementType + '"';
|
410
|
-
return converter(string);
|
411
|
-
};
|
412
|
-
|
413
397
|
var convertExtraOptionRequirement = function convertExtraOptionRequirement(requirementSpec, string, extraOptionReader) {
|
414
398
|
var main = null;
|
415
399
|
var extra = {};
|
416
400
|
for (var key in requirementSpec) {
|
417
401
|
if (key) {
|
418
402
|
var value = extraOptionReader(key);
|
419
|
-
if ('string' === typeof value) value =
|
403
|
+
if ('string' === typeof value) value = Utils__default.parseRequirement(requirementSpec[key], value);
|
420
404
|
extra[key] = value;
|
421
405
|
} else {
|
422
|
-
main =
|
406
|
+
main = Utils__default.parseRequirement(requirementSpec[key], string);
|
423
407
|
}
|
424
408
|
}
|
425
409
|
return [main, extra];
|
@@ -427,11 +411,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
427
411
|
|
428
412
|
// A Validator needs to implement the methods `validate` and `parseRequirements`
|
429
413
|
|
430
|
-
var
|
414
|
+
var Validator = function Validator(spec) {
|
431
415
|
$.extend(true, this, spec);
|
432
416
|
};
|
433
417
|
|
434
|
-
|
418
|
+
Validator.prototype = {
|
435
419
|
// Returns `true` iff the given `value` is valid according the given requirements.
|
436
420
|
validate: function validate(value, requirementFirstArg) {
|
437
421
|
if (this.fn) {
|
@@ -439,13 +423,19 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
439
423
|
|
440
424
|
if (arguments.length > 3) // If more args then value, requirement, instance...
|
441
425
|
requirementFirstArg = [].slice.call(arguments, 1, -1); // Skip first arg (value) and last (instance), combining the rest
|
442
|
-
return this.fn
|
426
|
+
return this.fn(value, requirementFirstArg);
|
443
427
|
}
|
444
428
|
|
445
429
|
if ($.isArray(value)) {
|
446
430
|
if (!this.validateMultiple) throw 'Validator `' + this.name + '` does not handle multiple values';
|
447
431
|
return this.validateMultiple.apply(this, arguments);
|
448
432
|
} else {
|
433
|
+
var instance = arguments[arguments.length - 1];
|
434
|
+
if (this.validateDate && instance._isDateInput()) {
|
435
|
+
arguments[0] = Utils__default.parse.date(arguments[0]);
|
436
|
+
if (arguments[0] === null) return false;
|
437
|
+
return this.validateDate.apply(this, arguments);
|
438
|
+
}
|
449
439
|
if (this.validateNumber) {
|
450
440
|
if (isNaN(value)) return false;
|
451
441
|
arguments[0] = parseFloat(arguments[0]);
|
@@ -469,12 +459,12 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
469
459
|
var type = this.requirementType;
|
470
460
|
if ($.isArray(type)) {
|
471
461
|
var values = convertArrayRequirement(requirements, type.length);
|
472
|
-
for (var i = 0; i < values.length; i++) values[i] =
|
462
|
+
for (var i = 0; i < values.length; i++) values[i] = Utils__default.parseRequirement(type[i], values[i]);
|
473
463
|
return values;
|
474
464
|
} else if ($.isPlainObject(type)) {
|
475
465
|
return convertExtraOptionRequirement(type, requirements, extraOptionReader);
|
476
466
|
} else {
|
477
|
-
return [
|
467
|
+
return [Utils__default.parseRequirement(type, requirements)];
|
478
468
|
}
|
479
469
|
},
|
480
470
|
// Defaults:
|
@@ -484,8 +474,8 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
484
474
|
|
485
475
|
};
|
486
476
|
|
487
|
-
var
|
488
|
-
this.__class__ = '
|
477
|
+
var ValidatorRegistry = function ValidatorRegistry(validators, catalog) {
|
478
|
+
this.__class__ = 'ValidatorRegistry';
|
489
479
|
|
490
480
|
// Default Parsley locale is en
|
491
481
|
this.locale = 'en';
|
@@ -493,7 +483,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
493
483
|
this.init(validators || {}, catalog || {});
|
494
484
|
};
|
495
485
|
|
496
|
-
var
|
486
|
+
var typeTesters = {
|
497
487
|
email: /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,
|
498
488
|
|
499
489
|
// Follow https://www.w3.org/TR/html5/infrastructure.html#floating-point-numbers
|
@@ -505,6 +495,12 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
505
495
|
|
506
496
|
alphanum: /^\w+$/i,
|
507
497
|
|
498
|
+
date: {
|
499
|
+
test: function test(value) {
|
500
|
+
return Utils__default.parse.date(value) !== null;
|
501
|
+
}
|
502
|
+
},
|
503
|
+
|
508
504
|
url: new RegExp("^" +
|
509
505
|
// protocol identifier
|
510
506
|
"(?:(?:https?|ftp)://)?" + // ** mod: make scheme optional
|
@@ -532,7 +528,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
532
528
|
// resource path
|
533
529
|
"(?:/\\S*)?" + "$", 'i')
|
534
530
|
};
|
535
|
-
|
531
|
+
typeTesters.range = typeTesters.number;
|
536
532
|
|
537
533
|
// See http://stackoverflow.com/a/10454560/8279
|
538
534
|
var decimalPlaces = function decimalPlaces(num) {
|
@@ -547,7 +543,32 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
547
543
|
match[2] ? +match[2] : 0));
|
548
544
|
};
|
549
545
|
|
550
|
-
|
546
|
+
// parseArguments('number', ['1', '2']) => [1, 2]
|
547
|
+
var ValidatorRegistry__parseArguments = function ValidatorRegistry__parseArguments(type, args) {
|
548
|
+
return args.map(Utils__default.parse[type]);
|
549
|
+
};
|
550
|
+
// operatorToValidator returns a validating function for an operator function, applied to the given type
|
551
|
+
var ValidatorRegistry__operatorToValidator = function ValidatorRegistry__operatorToValidator(type, operator) {
|
552
|
+
return function (value) {
|
553
|
+
for (var _len = arguments.length, requirementsAndInput = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
554
|
+
requirementsAndInput[_key - 1] = arguments[_key];
|
555
|
+
}
|
556
|
+
|
557
|
+
requirementsAndInput.pop(); // Get rid of `input` argument
|
558
|
+
return operator.apply(undefined, [value].concat(_toConsumableArray(ValidatorRegistry__parseArguments(type, requirementsAndInput))));
|
559
|
+
};
|
560
|
+
};
|
561
|
+
|
562
|
+
var ValidatorRegistry__comparisonOperator = function ValidatorRegistry__comparisonOperator(operator) {
|
563
|
+
return {
|
564
|
+
validateDate: ValidatorRegistry__operatorToValidator('date', operator),
|
565
|
+
validateNumber: ValidatorRegistry__operatorToValidator('number', operator),
|
566
|
+
requirementType: operator.length <= 2 ? 'string' : ['string', 'string'], // Support operators with a 1 or 2 requirement(s)
|
567
|
+
priority: 30
|
568
|
+
};
|
569
|
+
};
|
570
|
+
|
571
|
+
ValidatorRegistry.prototype = {
|
551
572
|
init: function init(validators, catalog) {
|
552
573
|
this.catalog = catalog;
|
553
574
|
// Copy prototype's validators:
|
@@ -607,8 +628,8 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
607
628
|
// Old API was addValidator(name, function, priority)
|
608
629
|
//
|
609
630
|
addValidator: function addValidator(name, arg1, arg2) {
|
610
|
-
if (this.validators[name])
|
611
|
-
|
631
|
+
if (this.validators[name]) Utils__default.warn('Validator "' + name + '" is already defined.');else if (Defaults.hasOwnProperty(name)) {
|
632
|
+
Utils__default.warn('"' + name + '" is a restricted keyword and is not a valid validator name.');
|
612
633
|
return;
|
613
634
|
}
|
614
635
|
return this._setValidator.apply(this, arguments);
|
@@ -616,14 +637,14 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
616
637
|
|
617
638
|
updateValidator: function updateValidator(name, arg1, arg2) {
|
618
639
|
if (!this.validators[name]) {
|
619
|
-
|
640
|
+
Utils__default.warn('Validator "' + name + '" is not already defined.');
|
620
641
|
return this.addValidator.apply(this, arguments);
|
621
642
|
}
|
622
643
|
return this._setValidator.apply(this, arguments);
|
623
644
|
},
|
624
645
|
|
625
646
|
removeValidator: function removeValidator(name) {
|
626
|
-
if (!this.validators[name])
|
647
|
+
if (!this.validators[name]) Utils__default.warn('Validator "' + name + '" is not defined.');
|
627
648
|
|
628
649
|
delete this.validators[name];
|
629
650
|
|
@@ -639,7 +660,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
639
660
|
};
|
640
661
|
}
|
641
662
|
if (!validator.validate) {
|
642
|
-
validator = new
|
663
|
+
validator = new Validator(validator);
|
643
664
|
}
|
644
665
|
this.validators[name] = validator;
|
645
666
|
|
@@ -705,11 +726,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
705
726
|
var _ref$base = _ref.base;
|
706
727
|
var base = _ref$base === undefined ? 0 : _ref$base;
|
707
728
|
|
708
|
-
var
|
709
|
-
if (!
|
729
|
+
var tester = typeTesters[type];
|
730
|
+
if (!tester) {
|
710
731
|
throw new Error('validator type `' + type + '` is not supported');
|
711
732
|
}
|
712
|
-
if (!
|
733
|
+
if (!tester.test(value)) return false;
|
713
734
|
if ('number' === type) {
|
714
735
|
if (!/^any$/i.test(step || '')) {
|
715
736
|
var nb = Number(value);
|
@@ -781,27 +802,15 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
781
802
|
requirementType: ['integer', 'integer'],
|
782
803
|
priority: 30
|
783
804
|
},
|
784
|
-
min: {
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
return value <= requirement;
|
794
|
-
},
|
795
|
-
requirementType: 'number',
|
796
|
-
priority: 30
|
797
|
-
},
|
798
|
-
range: {
|
799
|
-
validateNumber: function validateNumber(value, min, max) {
|
800
|
-
return value >= min && value <= max;
|
801
|
-
},
|
802
|
-
requirementType: ['number', 'number'],
|
803
|
-
priority: 30
|
804
|
-
},
|
805
|
+
min: ValidatorRegistry__comparisonOperator(function (value, requirement) {
|
806
|
+
return value >= requirement;
|
807
|
+
}),
|
808
|
+
max: ValidatorRegistry__comparisonOperator(function (value, requirement) {
|
809
|
+
return value <= requirement;
|
810
|
+
}),
|
811
|
+
range: ValidatorRegistry__comparisonOperator(function (value, min, max) {
|
812
|
+
return value >= min && value <= max;
|
813
|
+
}),
|
805
814
|
equalto: {
|
806
815
|
validateString: function validateString(value, refOrValue) {
|
807
816
|
var $reference = $(refOrValue);
|
@@ -812,7 +821,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
812
821
|
}
|
813
822
|
};
|
814
823
|
|
815
|
-
var
|
824
|
+
var UI = {};
|
816
825
|
|
817
826
|
var diffResults = function diffResults(newResult, oldResult, deep) {
|
818
827
|
var added = [];
|
@@ -836,7 +845,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
836
845
|
};
|
837
846
|
};
|
838
847
|
|
839
|
-
|
848
|
+
UI.Form = {
|
840
849
|
|
841
850
|
_actualizeTriggers: function _actualizeTriggers() {
|
842
851
|
var _this2 = this;
|
@@ -844,7 +853,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
844
853
|
this.$element.on('submit.Parsley', function (evt) {
|
845
854
|
_this2.onSubmitValidate(evt);
|
846
855
|
});
|
847
|
-
this.$element.on('click.Parsley',
|
856
|
+
this.$element.on('click.Parsley', Utils__default._SubmitSelector, function (evt) {
|
848
857
|
_this2.onSubmitButton(evt);
|
849
858
|
});
|
850
859
|
|
@@ -879,7 +888,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
879
888
|
|
880
889
|
};
|
881
890
|
|
882
|
-
|
891
|
+
UI.Field = {
|
883
892
|
|
884
893
|
_reflowUI: function _reflowUI() {
|
885
894
|
this._buildUI();
|
@@ -1075,7 +1084,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1075
1084
|
if (0 !== this._ui.$errorsWrapper.parent().length) return this._ui.$errorsWrapper.parent();
|
1076
1085
|
|
1077
1086
|
if ('string' === typeof this.options.errorsContainer) {
|
1078
|
-
if ($(this.options.errorsContainer).length) return $(this.options.errorsContainer).append(this._ui.$errorsWrapper);else
|
1087
|
+
if ($(this.options.errorsContainer).length) return $(this.options.errorsContainer).append(this._ui.$errorsWrapper);else Utils__default.warn('The errors container `' + this.options.errorsContainer + '` does not exist in DOM');
|
1079
1088
|
} else if ('function' === typeof this.options.errorsContainer) $errorsContainer = this.options.errorsContainer.call(this, this);
|
1080
1089
|
|
1081
1090
|
if ('undefined' !== typeof $errorsContainer && $errorsContainer.length) return $errorsContainer.append(this._ui.$errorsWrapper);
|
@@ -1091,9 +1100,9 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1091
1100
|
|
1092
1101
|
// Remove Parsley events already bound on this field
|
1093
1102
|
$toBind.off('.Parsley');
|
1094
|
-
if (this._failedOnce) $toBind.on(
|
1103
|
+
if (this._failedOnce) $toBind.on(Utils__default.namespaceEvents(this.options.triggerAfterFailure, 'Parsley'), function () {
|
1095
1104
|
_this3._validateIfNeeded();
|
1096
|
-
});else if (trigger =
|
1105
|
+
});else if (trigger = Utils__default.namespaceEvents(this.options.trigger, 'Parsley')) {
|
1097
1106
|
$toBind.on(trigger, function (event) {
|
1098
1107
|
_this3._validateIfNeeded(event);
|
1099
1108
|
});
|
@@ -1156,8 +1165,8 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1156
1165
|
}
|
1157
1166
|
};
|
1158
1167
|
|
1159
|
-
var
|
1160
|
-
this.__class__ = '
|
1168
|
+
var Form = function Form(element, domOptions, options) {
|
1169
|
+
this.__class__ = 'Form';
|
1161
1170
|
|
1162
1171
|
this.$element = $(element);
|
1163
1172
|
this.domOptions = domOptions;
|
@@ -1168,9 +1177,9 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1168
1177
|
this.validationResult = null;
|
1169
1178
|
};
|
1170
1179
|
|
1171
|
-
var
|
1180
|
+
var Form__statusMapping = { pending: null, resolved: true, rejected: false };
|
1172
1181
|
|
1173
|
-
|
1182
|
+
Form.prototype = {
|
1174
1183
|
onSubmitValidate: function onSubmitValidate(event) {
|
1175
1184
|
var _this5 = this;
|
1176
1185
|
|
@@ -1178,7 +1187,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1178
1187
|
if (true === event.parsley) return;
|
1179
1188
|
|
1180
1189
|
// If we didn't come here through a submit button, use the first one in the form
|
1181
|
-
var $submitSource = this._$submitSource || this.$element.find(
|
1190
|
+
var $submitSource = this._$submitSource || this.$element.find(Utils__default._SubmitSelector).first();
|
1182
1191
|
this._$submitSource = null;
|
1183
1192
|
this.$element.find('.parsley-synthetic-submit-button').prop('disabled', true);
|
1184
1193
|
if ($submitSource.is('[formnovalidate]')) return;
|
@@ -1226,7 +1235,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1226
1235
|
// Consider using `whenValidate` instead.
|
1227
1236
|
validate: function validate(options) {
|
1228
1237
|
if (arguments.length >= 1 && !$.isPlainObject(options)) {
|
1229
|
-
|
1238
|
+
Utils__default.warnOnce('Calling validate on a parsley form without passing arguments as an object is deprecated.');
|
1230
1239
|
|
1231
1240
|
var _arguments = _slice.call(arguments);
|
1232
1241
|
|
@@ -1236,11 +1245,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1236
1245
|
|
1237
1246
|
options = { group: group, force: force, event: event };
|
1238
1247
|
}
|
1239
|
-
return
|
1248
|
+
return Form__statusMapping[this.whenValidate(options).state()];
|
1240
1249
|
},
|
1241
1250
|
|
1242
1251
|
whenValidate: function whenValidate() {
|
1243
|
-
var
|
1252
|
+
var _Utils__default$all$done$fail$always,
|
1244
1253
|
_this6 = this;
|
1245
1254
|
|
1246
1255
|
var _ref7 = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
@@ -1252,7 +1261,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1252
1261
|
this.submitEvent = event;
|
1253
1262
|
if (event) {
|
1254
1263
|
this.submitEvent = $.extend({}, event, { preventDefault: function preventDefault() {
|
1255
|
-
|
1264
|
+
Utils__default.warnOnce("Using `this.submitEvent.preventDefault()` is deprecated; instead, call `this.validationResult = false`");
|
1256
1265
|
_this6.validationResult = false;
|
1257
1266
|
} });
|
1258
1267
|
}
|
@@ -1270,7 +1279,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1270
1279
|
});
|
1271
1280
|
});
|
1272
1281
|
|
1273
|
-
return (
|
1282
|
+
return (_Utils__default$all$done$fail$always = Utils__default.all(promises).done(function () {
|
1274
1283
|
_this6._trigger('success');
|
1275
1284
|
}).fail(function () {
|
1276
1285
|
_this6.validationResult = false;
|
@@ -1278,7 +1287,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1278
1287
|
_this6._trigger('error');
|
1279
1288
|
}).always(function () {
|
1280
1289
|
_this6._trigger('validated');
|
1281
|
-
})).pipe.apply(
|
1290
|
+
})).pipe.apply(_Utils__default$all$done$fail$always, _toConsumableArray(this._pipeAccordingToValidationResult()));
|
1282
1291
|
},
|
1283
1292
|
|
1284
1293
|
// Iterate over refreshed fields, and stop on first failure.
|
@@ -1287,7 +1296,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1287
1296
|
// Prefer using `whenValid` instead.
|
1288
1297
|
isValid: function isValid(options) {
|
1289
1298
|
if (arguments.length >= 1 && !$.isPlainObject(options)) {
|
1290
|
-
|
1299
|
+
Utils__default.warnOnce('Calling isValid on a parsley form without passing arguments as an object is deprecated.');
|
1291
1300
|
|
1292
1301
|
var _arguments2 = _slice.call(arguments);
|
1293
1302
|
|
@@ -1296,7 +1305,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1296
1305
|
|
1297
1306
|
options = { group: group, force: force };
|
1298
1307
|
}
|
1299
|
-
return
|
1308
|
+
return Form__statusMapping[this.whenValid(options).state()];
|
1300
1309
|
},
|
1301
1310
|
|
1302
1311
|
// Iterate over refreshed fields and validate them.
|
@@ -1317,7 +1326,27 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1317
1326
|
return field.whenValid({ group: group, force: force });
|
1318
1327
|
});
|
1319
1328
|
});
|
1320
|
-
return
|
1329
|
+
return Utils__default.all(promises);
|
1330
|
+
},
|
1331
|
+
|
1332
|
+
// Reset UI
|
1333
|
+
reset: function reset() {
|
1334
|
+
// Form case: emit a reset event for each field
|
1335
|
+
for (var i = 0; i < this.fields.length; i++) this.fields[i].reset();
|
1336
|
+
|
1337
|
+
this._trigger('reset');
|
1338
|
+
},
|
1339
|
+
|
1340
|
+
// Destroy Parsley instance (+ UI)
|
1341
|
+
destroy: function destroy() {
|
1342
|
+
// Field case: emit destroy event to clean UI and then destroy stored instance
|
1343
|
+
this._destroyUI();
|
1344
|
+
|
1345
|
+
// Form case: destroy all its fields and then destroy stored instance
|
1346
|
+
for (var i = 0; i < this.fields.length; i++) this.fields[i].destroy();
|
1347
|
+
|
1348
|
+
this.$element.removeData('Parsley');
|
1349
|
+
this._trigger('destroy');
|
1321
1350
|
},
|
1322
1351
|
|
1323
1352
|
_refreshFields: function _refreshFields() {
|
@@ -1336,15 +1365,18 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1336
1365
|
_this8.$element.find(_this8.options.inputs).not(_this8.options.excluded).each(function (_, element) {
|
1337
1366
|
var fieldInstance = new window.Parsley.Factory(element, {}, _this8);
|
1338
1367
|
|
1339
|
-
// Only add valid and not excluded `
|
1340
|
-
if (('
|
1341
|
-
|
1342
|
-
_this8.
|
1368
|
+
// Only add valid and not excluded `Field` and `FieldMultiple` children
|
1369
|
+
if (('Field' === fieldInstance.__class__ || 'FieldMultiple' === fieldInstance.__class__) && true !== fieldInstance.options.excluded) {
|
1370
|
+
var uniqueId = fieldInstance.__class__ + '-' + fieldInstance.__id__;
|
1371
|
+
if ('undefined' === typeof _this8.fieldsMappedById[uniqueId]) {
|
1372
|
+
_this8.fieldsMappedById[uniqueId] = fieldInstance;
|
1373
|
+
_this8.fields.push(fieldInstance);
|
1374
|
+
}
|
1343
1375
|
}
|
1344
1376
|
});
|
1345
1377
|
|
1346
|
-
$.each(
|
1347
|
-
field.
|
1378
|
+
$.each(Utils__default.difference(oldFields, _this8.fields), function (_, field) {
|
1379
|
+
field.reset();
|
1348
1380
|
});
|
1349
1381
|
});
|
1350
1382
|
return this;
|
@@ -1376,11 +1408,9 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1376
1408
|
|
1377
1409
|
};
|
1378
1410
|
|
1379
|
-
var
|
1380
|
-
if (!/ParsleyField/.test(parsleyField.__class__)) throw new Error('ParsleyField or ParsleyFieldMultiple instance expected');
|
1381
|
-
|
1411
|
+
var Constraint = function Constraint(parsleyField, name, requirements, priority, isDomConstraint) {
|
1382
1412
|
var validatorSpec = window.Parsley._validatorRegistry.validators[name];
|
1383
|
-
var validator = new
|
1413
|
+
var validator = new Validator(validatorSpec);
|
1384
1414
|
|
1385
1415
|
$.extend(this, {
|
1386
1416
|
validator: validator,
|
@@ -1397,7 +1427,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1397
1427
|
return cap + str.slice(1);
|
1398
1428
|
};
|
1399
1429
|
|
1400
|
-
|
1430
|
+
Constraint.prototype = {
|
1401
1431
|
validate: function validate(value, instance) {
|
1402
1432
|
var _validator;
|
1403
1433
|
|
@@ -1413,8 +1443,8 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1413
1443
|
}
|
1414
1444
|
};
|
1415
1445
|
|
1416
|
-
var
|
1417
|
-
this.__class__ = '
|
1446
|
+
var Field = function Field(field, domOptions, options, parsleyFormInstance) {
|
1447
|
+
this.__class__ = 'Field';
|
1418
1448
|
|
1419
1449
|
this.$element = $(field);
|
1420
1450
|
|
@@ -1437,14 +1467,14 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1437
1467
|
|
1438
1468
|
var parsley_field__statusMapping = { pending: null, resolved: true, rejected: false };
|
1439
1469
|
|
1440
|
-
|
1470
|
+
Field.prototype = {
|
1441
1471
|
// # Public API
|
1442
|
-
// Validate field and trigger some events for mainly `
|
1472
|
+
// Validate field and trigger some events for mainly `UI`
|
1443
1473
|
// @returns `true`, an array of the validators that failed, or
|
1444
1474
|
// `null` if validation is not finished. Prefer using whenValidate
|
1445
1475
|
validate: function validate(options) {
|
1446
1476
|
if (arguments.length >= 1 && !$.isPlainObject(options)) {
|
1447
|
-
|
1477
|
+
Utils__default.warnOnce('Calling validate on a parsley field without passing arguments as an object is deprecated.');
|
1448
1478
|
options = { options: options };
|
1449
1479
|
}
|
1450
1480
|
var promise = this.whenValidate(options);
|
@@ -1460,7 +1490,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1460
1490
|
}
|
1461
1491
|
},
|
1462
1492
|
|
1463
|
-
// Validate field and trigger some events for mainly `
|
1493
|
+
// Validate field and trigger some events for mainly `UI`
|
1464
1494
|
// @returns a promise that succeeds only when all validations do
|
1465
1495
|
// or `undefined` if field is not in the given `group`.
|
1466
1496
|
whenValidate: function whenValidate() {
|
@@ -1518,7 +1548,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1518
1548
|
// See also `whenValid`.
|
1519
1549
|
isValid: function isValid(options) {
|
1520
1550
|
if (arguments.length >= 1 && !$.isPlainObject(options)) {
|
1521
|
-
|
1551
|
+
Utils__default.warnOnce('Calling isValid on a parsley field without passing arguments as an object is deprecated.');
|
1522
1552
|
|
1523
1553
|
var _arguments3 = _slice.call(arguments);
|
1524
1554
|
|
@@ -1569,13 +1599,13 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1569
1599
|
$.each(groupedConstraints, function (_, constraints) {
|
1570
1600
|
// Process one group of constraints at a time, we validate the constraints
|
1571
1601
|
// and combine the promises together.
|
1572
|
-
var promise =
|
1602
|
+
var promise = Utils__default.all($.map(constraints, function (constraint) {
|
1573
1603
|
return _this11._validateConstraint(value, constraint);
|
1574
1604
|
}));
|
1575
1605
|
promises.push(promise);
|
1576
1606
|
if (promise.state() === 'rejected') return false; // Interrupt processing if a group has already failed
|
1577
1607
|
});
|
1578
|
-
return
|
1608
|
+
return Utils__default.all(promises);
|
1579
1609
|
},
|
1580
1610
|
|
1581
1611
|
// @returns a promise
|
@@ -1586,7 +1616,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1586
1616
|
// Map false to a failed promise
|
1587
1617
|
if (false === result) result = $.Deferred().reject();
|
1588
1618
|
// Make sure we return a promise and that we record failures
|
1589
|
-
return
|
1619
|
+
return Utils__default.all([result]).fail(function (errorMessage) {
|
1590
1620
|
if (!(_this12.validationResult instanceof Array)) _this12.validationResult = [];
|
1591
1621
|
_this12.validationResult.push({
|
1592
1622
|
assert: constraint,
|
@@ -1608,6 +1638,21 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1608
1638
|
return this._handleWhitespace(value);
|
1609
1639
|
},
|
1610
1640
|
|
1641
|
+
// Reset UI
|
1642
|
+
reset: function reset() {
|
1643
|
+
this._resetUI();
|
1644
|
+
return this._trigger('reset');
|
1645
|
+
},
|
1646
|
+
|
1647
|
+
// Destroy Parsley instance (+ UI)
|
1648
|
+
destroy: function destroy() {
|
1649
|
+
// Field case: emit destroy event to clean UI and then destroy stored instance
|
1650
|
+
this._destroyUI();
|
1651
|
+
this.$element.removeData('Parsley');
|
1652
|
+
this.$element.removeData('FieldMultiple');
|
1653
|
+
this._trigger('destroy');
|
1654
|
+
},
|
1655
|
+
|
1611
1656
|
// Actualize options that could have change since previous validation
|
1612
1657
|
// Re-bind accordingly constraints (could be some new, removed or updated)
|
1613
1658
|
refreshConstraints: function refreshConstraints() {
|
@@ -1625,7 +1670,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1625
1670
|
addConstraint: function addConstraint(name, requirements, priority, isDomConstraint) {
|
1626
1671
|
|
1627
1672
|
if (window.Parsley._validatorRegistry.validators[name]) {
|
1628
|
-
var constraint = new
|
1673
|
+
var constraint = new Constraint(this, name, requirements, priority, isDomConstraint);
|
1629
1674
|
|
1630
1675
|
// if constraint already exist, delete it and push new version
|
1631
1676
|
if ('undefined' !== this.constraintsByName[constraint.name]) this.removeConstraint(constraint.name);
|
@@ -1686,13 +1731,13 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1686
1731
|
if ('string' === typeof this.$element.attr('pattern')) this.addConstraint('pattern', this.$element.attr('pattern'), undefined, true);
|
1687
1732
|
|
1688
1733
|
// range
|
1689
|
-
if (
|
1734
|
+
if ('undefined' !== typeof this.$element.attr('min') && 'undefined' !== typeof this.$element.attr('max')) this.addConstraint('range', [this.$element.attr('min'), this.$element.attr('max')], undefined, true);
|
1690
1735
|
|
1691
1736
|
// HTML5 min
|
1692
|
-
else if (
|
1737
|
+
else if ('undefined' !== typeof this.$element.attr('min')) this.addConstraint('min', this.$element.attr('min'), undefined, true);
|
1693
1738
|
|
1694
1739
|
// HTML5 max
|
1695
|
-
else if (
|
1740
|
+
else if ('undefined' !== typeof this.$element.attr('max')) this.addConstraint('max', this.$element.attr('max'), undefined, true);
|
1696
1741
|
|
1697
1742
|
// length
|
1698
1743
|
if ('undefined' !== typeof this.$element.attr('minlength') && 'undefined' !== typeof this.$element.attr('maxlength')) this.addConstraint('length', [this.$element.attr('minlength'), this.$element.attr('maxlength')], undefined, true);
|
@@ -1715,7 +1760,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1715
1760
|
base: this.$element.attr('min') || this.$element.attr('value')
|
1716
1761
|
}], undefined, true);
|
1717
1762
|
// Regular other HTML5 supported types
|
1718
|
-
} else if (/^(email|url|range)$/i.test(type)) {
|
1763
|
+
} else if (/^(email|url|range|date)$/i.test(type)) {
|
1719
1764
|
return this.addConstraint('type', type, undefined, true);
|
1720
1765
|
}
|
1721
1766
|
return this;
|
@@ -1740,15 +1785,20 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1740
1785
|
// Use `data-parsley-whitespace="squish"` to auto squish input value
|
1741
1786
|
// Use `data-parsley-whitespace="trim"` to auto trim input value
|
1742
1787
|
_handleWhitespace: function _handleWhitespace(value) {
|
1743
|
-
if (true === this.options.trimValue)
|
1788
|
+
if (true === this.options.trimValue) Utils__default.warnOnce('data-parsley-trim-value="true" is deprecated, please use data-parsley-whitespace="trim"');
|
1744
1789
|
|
1745
1790
|
if ('squish' === this.options.whitespace) value = value.replace(/\s{2,}/g, ' ');
|
1746
1791
|
|
1747
|
-
if ('trim' === this.options.whitespace || 'squish' === this.options.whitespace || true === this.options.trimValue) value =
|
1792
|
+
if ('trim' === this.options.whitespace || 'squish' === this.options.whitespace || true === this.options.trimValue) value = Utils__default.trimString(value);
|
1748
1793
|
|
1749
1794
|
return value;
|
1750
1795
|
},
|
1751
1796
|
|
1797
|
+
_isDateInput: function _isDateInput() {
|
1798
|
+
var c = this.constraintsByName.type;
|
1799
|
+
return c && c.requirements === 'date';
|
1800
|
+
},
|
1801
|
+
|
1752
1802
|
// Internal only.
|
1753
1803
|
// Returns the constraints, grouped by descending priority.
|
1754
1804
|
// The result is thus an array of arrays of constraints.
|
@@ -1774,13 +1824,13 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1774
1824
|
|
1775
1825
|
};
|
1776
1826
|
|
1777
|
-
var parsley_field =
|
1827
|
+
var parsley_field = Field;
|
1778
1828
|
|
1779
|
-
var
|
1780
|
-
this.__class__ = '
|
1829
|
+
var Multiple = function Multiple() {
|
1830
|
+
this.__class__ = 'FieldMultiple';
|
1781
1831
|
};
|
1782
1832
|
|
1783
|
-
|
1833
|
+
Multiple.prototype = {
|
1784
1834
|
// Add new `$element` sibling for multiple field
|
1785
1835
|
addElement: function addElement($element) {
|
1786
1836
|
this.$elements.push($element);
|
@@ -1788,7 +1838,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1788
1838
|
return this;
|
1789
1839
|
},
|
1790
1840
|
|
1791
|
-
// See `
|
1841
|
+
// See `Field.refreshConstraints()`
|
1792
1842
|
refreshConstraints: function refreshConstraints() {
|
1793
1843
|
var fieldConstraints;
|
1794
1844
|
|
@@ -1810,7 +1860,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1810
1860
|
continue;
|
1811
1861
|
}
|
1812
1862
|
|
1813
|
-
fieldConstraints = this.$elements[i].data('
|
1863
|
+
fieldConstraints = this.$elements[i].data('FieldMultiple').refreshConstraints().constraints;
|
1814
1864
|
|
1815
1865
|
for (var j = 0; j < fieldConstraints.length; j++) this.addConstraint(fieldConstraints[j].name, fieldConstraints[j].requirements, fieldConstraints[j].priority, fieldConstraints[j].isDomConstraint);
|
1816
1866
|
}
|
@@ -1818,7 +1868,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1818
1868
|
return this;
|
1819
1869
|
},
|
1820
1870
|
|
1821
|
-
// See `
|
1871
|
+
// See `Field.getValue()`
|
1822
1872
|
getValue: function getValue() {
|
1823
1873
|
// Value could be overriden in DOM
|
1824
1874
|
if ('function' === typeof this.options.value) return this.options.value(this);else if ('undefined' !== typeof this.options.value) return this.options.value;
|
@@ -1851,14 +1901,14 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1851
1901
|
}
|
1852
1902
|
};
|
1853
1903
|
|
1854
|
-
var
|
1904
|
+
var Factory = function Factory(element, options, parsleyFormInstance) {
|
1855
1905
|
this.$element = $(element);
|
1856
1906
|
|
1857
1907
|
// If the element has already been bound, returns its saved Parsley instance
|
1858
1908
|
var savedparsleyFormInstance = this.$element.data('Parsley');
|
1859
1909
|
if (savedparsleyFormInstance) {
|
1860
1910
|
|
1861
|
-
// If the saved instance has been bound without a
|
1911
|
+
// If the saved instance has been bound without a Form parent and there is one given in this call, add it
|
1862
1912
|
if ('undefined' !== typeof parsleyFormInstance && savedparsleyFormInstance.parent === window.Parsley) {
|
1863
1913
|
savedparsleyFormInstance.parent = parsleyFormInstance;
|
1864
1914
|
savedparsleyFormInstance._resetOptions(savedparsleyFormInstance.options);
|
@@ -1874,25 +1924,25 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1874
1924
|
// Parsley must be instantiated with a DOM element or jQuery $element
|
1875
1925
|
if (!this.$element.length) throw new Error('You must bind Parsley on an existing element.');
|
1876
1926
|
|
1877
|
-
if ('undefined' !== typeof parsleyFormInstance && '
|
1927
|
+
if ('undefined' !== typeof parsleyFormInstance && 'Form' !== parsleyFormInstance.__class__) throw new Error('Parent instance must be a Form instance');
|
1878
1928
|
|
1879
1929
|
this.parent = parsleyFormInstance || window.Parsley;
|
1880
1930
|
return this.init(options);
|
1881
1931
|
};
|
1882
1932
|
|
1883
|
-
|
1933
|
+
Factory.prototype = {
|
1884
1934
|
init: function init(options) {
|
1885
1935
|
this.__class__ = 'Parsley';
|
1886
|
-
this.__version__ = '2.
|
1887
|
-
this.__id__ =
|
1936
|
+
this.__version__ = '2.7.0';
|
1937
|
+
this.__id__ = Utils__default.generateID();
|
1888
1938
|
|
1889
1939
|
// Pre-compute options
|
1890
1940
|
this._resetOptions(options);
|
1891
1941
|
|
1892
|
-
// A
|
1893
|
-
if (this.$element.is('form') ||
|
1942
|
+
// A Form instance is obviously a `<form>` element but also every node that is not an input and has the `data-parsley-validate` attribute
|
1943
|
+
if (this.$element.is('form') || Utils__default.checkAttr(this.$element, this.options.namespace, 'validate') && !this.$element.is(this.options.inputs)) return this.bind('parsleyForm');
|
1894
1944
|
|
1895
|
-
// Every other element is bound as a `
|
1945
|
+
// Every other element is bound as a `Field` or `FieldMultiple`
|
1896
1946
|
return this.isMultiple() ? this.handleMultiple() : this.bind('parsleyField');
|
1897
1947
|
},
|
1898
1948
|
|
@@ -1920,7 +1970,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1920
1970
|
|
1921
1971
|
// Else for radio / checkboxes, we need a `name` or `data-parsley-multiple` to properly bind it
|
1922
1972
|
} else if (!this.options.multiple) {
|
1923
|
-
|
1973
|
+
Utils__default.warn('To be bound by Parsley, a radio, a checkbox and a multiple select input must have either a name or a multiple option.', this.$element);
|
1924
1974
|
return this;
|
1925
1975
|
}
|
1926
1976
|
|
@@ -1940,7 +1990,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1940
1990
|
parsleyMultipleInstance = $($previouslyRelated.get(i)).data('Parsley');
|
1941
1991
|
if ('undefined' !== typeof parsleyMultipleInstance) {
|
1942
1992
|
|
1943
|
-
if (!this.$element.data('
|
1993
|
+
if (!this.$element.data('FieldMultiple')) {
|
1944
1994
|
parsleyMultipleInstance.addElement(this.$element);
|
1945
1995
|
}
|
1946
1996
|
|
@@ -1948,35 +1998,35 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1948
1998
|
}
|
1949
1999
|
}
|
1950
2000
|
|
1951
|
-
// Create a secret
|
1952
|
-
// And will be useful later to access classic `
|
2001
|
+
// Create a secret Field instance for every multiple field. It will be stored in `data('FieldMultiple')`
|
2002
|
+
// And will be useful later to access classic `Field` stuff while being in a `FieldMultiple` instance
|
1953
2003
|
this.bind('parsleyField', true);
|
1954
2004
|
|
1955
2005
|
return parsleyMultipleInstance || this.bind('parsleyFieldMultiple');
|
1956
2006
|
},
|
1957
2007
|
|
1958
|
-
// Return proper `
|
2008
|
+
// Return proper `Form`, `Field` or `FieldMultiple`
|
1959
2009
|
bind: function bind(type, doNotStore) {
|
1960
2010
|
var parsleyInstance;
|
1961
2011
|
|
1962
2012
|
switch (type) {
|
1963
2013
|
case 'parsleyForm':
|
1964
|
-
parsleyInstance = $.extend(new
|
2014
|
+
parsleyInstance = $.extend(new Form(this.$element, this.domOptions, this.options), new Base(), window.ParsleyExtend)._bindFields();
|
1965
2015
|
break;
|
1966
2016
|
case 'parsleyField':
|
1967
|
-
parsleyInstance = $.extend(new parsley_field(this.$element, this.domOptions, this.options, this.parent), new
|
2017
|
+
parsleyInstance = $.extend(new parsley_field(this.$element, this.domOptions, this.options, this.parent), new Base(), window.ParsleyExtend);
|
1968
2018
|
break;
|
1969
2019
|
case 'parsleyFieldMultiple':
|
1970
|
-
parsleyInstance = $.extend(new parsley_field(this.$element, this.domOptions, this.options, this.parent), new
|
2020
|
+
parsleyInstance = $.extend(new parsley_field(this.$element, this.domOptions, this.options, this.parent), new Multiple(), new Base(), window.ParsleyExtend)._init();
|
1971
2021
|
break;
|
1972
2022
|
default:
|
1973
2023
|
throw new Error(type + 'is not a supported Parsley type');
|
1974
2024
|
}
|
1975
2025
|
|
1976
|
-
if (this.options.multiple)
|
2026
|
+
if (this.options.multiple) Utils__default.setAttr(this.$element, this.options.namespace, 'multiple', this.options.multiple);
|
1977
2027
|
|
1978
2028
|
if ('undefined' !== typeof doNotStore) {
|
1979
|
-
this.$element.data('
|
2029
|
+
this.$element.data('FieldMultiple', parsleyInstance);
|
1980
2030
|
|
1981
2031
|
return parsleyInstance;
|
1982
2032
|
}
|
@@ -1984,7 +2034,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1984
2034
|
// Store the freshly bound instance in a DOM element for later access using jQuery `data()`
|
1985
2035
|
this.$element.data('Parsley', parsleyInstance);
|
1986
2036
|
|
1987
|
-
// Tell the world we have a new
|
2037
|
+
// Tell the world we have a new Form or Field instance!
|
1988
2038
|
parsleyInstance._actualizeTriggers();
|
1989
2039
|
parsleyInstance._trigger('init');
|
1990
2040
|
|
@@ -1997,23 +2047,23 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
1997
2047
|
throw "The loaded version of jQuery is too old. Please upgrade to 1.8.x or better.";
|
1998
2048
|
}
|
1999
2049
|
if (!vernums.forEach) {
|
2000
|
-
|
2050
|
+
Utils__default.warn('Parsley requires ES5 to run properly. Please include https://github.com/es-shims/es5-shim');
|
2001
2051
|
}
|
2002
2052
|
// Inherit `on`, `off` & `trigger` to Parsley:
|
2003
|
-
var Parsley = $.extend(new
|
2053
|
+
var Parsley = $.extend(new Base(), {
|
2004
2054
|
$element: $(document),
|
2005
2055
|
actualizeOptions: null,
|
2006
2056
|
_resetOptions: null,
|
2007
|
-
Factory:
|
2008
|
-
version: '2.
|
2057
|
+
Factory: Factory,
|
2058
|
+
version: '2.7.0'
|
2009
2059
|
});
|
2010
2060
|
|
2011
|
-
// Supplement
|
2061
|
+
// Supplement Field and Form with Base
|
2012
2062
|
// This way, the constructors will have access to those methods
|
2013
|
-
$.extend(parsley_field.prototype,
|
2014
|
-
$.extend(
|
2063
|
+
$.extend(parsley_field.prototype, UI.Field, Base.prototype);
|
2064
|
+
$.extend(Form.prototype, UI.Form, Base.prototype);
|
2015
2065
|
// Inherit actualizeOptions and _resetOptions:
|
2016
|
-
$.extend(
|
2066
|
+
$.extend(Factory.prototype, Base.prototype);
|
2017
2067
|
|
2018
2068
|
// ### jQuery API
|
2019
2069
|
// `$('.elem').parsley(options)` or `$('.elem').psly(options)`
|
@@ -2030,58 +2080,67 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
2030
2080
|
|
2031
2081
|
// Return undefined if applied to non existing DOM element
|
2032
2082
|
if (!$(this).length) {
|
2033
|
-
|
2083
|
+
Utils__default.warn('You must bind Parsley on an existing element.');
|
2034
2084
|
|
2035
2085
|
return;
|
2036
2086
|
}
|
2037
2087
|
|
2038
|
-
return new
|
2088
|
+
return new Factory(this, options);
|
2039
2089
|
};
|
2040
2090
|
|
2041
|
-
// ###
|
2091
|
+
// ### Field and Form extension
|
2042
2092
|
// Ensure the extension is now defined if it wasn't previously
|
2043
2093
|
if ('undefined' === typeof window.ParsleyExtend) window.ParsleyExtend = {};
|
2044
2094
|
|
2045
2095
|
// ### Parsley config
|
2046
2096
|
// Inherit from ParsleyDefault, and copy over any existing values
|
2047
|
-
Parsley.options = $.extend(
|
2097
|
+
Parsley.options = $.extend(Utils__default.objectCreate(Defaults), window.ParsleyConfig);
|
2048
2098
|
window.ParsleyConfig = Parsley.options; // Old way of accessing global options
|
2049
2099
|
|
2050
2100
|
// ### Globals
|
2051
2101
|
window.Parsley = window.psly = Parsley;
|
2052
|
-
|
2102
|
+
Parsley.Utils = Utils__default;
|
2103
|
+
window.ParsleyUtils = {};
|
2104
|
+
$.each(Utils__default, function (key, value) {
|
2105
|
+
if ('function' === typeof value) {
|
2106
|
+
window.ParsleyUtils[key] = function () {
|
2107
|
+
Utils__default.warnOnce('Accessing `window.ParsleyUtils` is deprecated. Use `window.Parsley.Utils` instead.');
|
2108
|
+
return Utils__default[key].apply(Utils__default, arguments);
|
2109
|
+
};
|
2110
|
+
}
|
2111
|
+
});
|
2053
2112
|
|
2054
2113
|
// ### Define methods that forward to the registry, and deprecate all access except through window.Parsley
|
2055
|
-
var registry = window.Parsley._validatorRegistry = new
|
2114
|
+
var registry = window.Parsley._validatorRegistry = new ValidatorRegistry(window.ParsleyConfig.validators, window.ParsleyConfig.i18n);
|
2056
2115
|
window.ParsleyValidator = {};
|
2057
2116
|
$.each('setLocale addCatalog addMessage addMessages getErrorMessage formatMessage addValidator updateValidator removeValidator'.split(' '), function (i, method) {
|
2058
2117
|
window.Parsley[method] = $.proxy(registry, method);
|
2059
2118
|
window.ParsleyValidator[method] = function () {
|
2060
2119
|
var _window$Parsley;
|
2061
2120
|
|
2062
|
-
|
2121
|
+
Utils__default.warnOnce('Accessing the method \'' + method + '\' through Validator is deprecated. Simply call \'window.Parsley.' + method + '(...)\'');
|
2063
2122
|
return (_window$Parsley = window.Parsley)[method].apply(_window$Parsley, arguments);
|
2064
2123
|
};
|
2065
2124
|
});
|
2066
2125
|
|
2067
|
-
// ###
|
2126
|
+
// ### UI
|
2068
2127
|
// Deprecated global object
|
2069
|
-
window.Parsley.UI =
|
2128
|
+
window.Parsley.UI = UI;
|
2070
2129
|
window.ParsleyUI = {
|
2071
2130
|
removeError: function removeError(instance, name, doNotUpdateClass) {
|
2072
2131
|
var updateClass = true !== doNotUpdateClass;
|
2073
|
-
|
2132
|
+
Utils__default.warnOnce('Accessing UI is deprecated. Call \'removeError\' on the instance directly. Please comment in issue 1073 as to your need to call this method.');
|
2074
2133
|
return instance.removeError(name, { updateClass: updateClass });
|
2075
2134
|
},
|
2076
2135
|
getErrorsMessages: function getErrorsMessages(instance) {
|
2077
|
-
|
2136
|
+
Utils__default.warnOnce('Accessing UI is deprecated. Call \'getErrorsMessages\' on the instance directly.');
|
2078
2137
|
return instance.getErrorsMessages();
|
2079
2138
|
}
|
2080
2139
|
};
|
2081
2140
|
$.each('addError updateError'.split(' '), function (i, method) {
|
2082
2141
|
window.ParsleyUI[method] = function (instance, name, message, assert, doNotUpdateClass) {
|
2083
2142
|
var updateClass = true !== doNotUpdateClass;
|
2084
|
-
|
2143
|
+
Utils__default.warnOnce('Accessing UI is deprecated. Call \'' + method + '\' on the instance directly. Please comment in issue 1073 as to your need to call this method.');
|
2085
2144
|
return instance[method](name, { message: message, assert: assert, updateClass: updateClass });
|
2086
2145
|
};
|
2087
2146
|
});
|
@@ -2097,7 +2156,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
2097
2156
|
|
2098
2157
|
var o = $({});
|
2099
2158
|
var deprecated = function deprecated() {
|
2100
|
-
|
2159
|
+
Utils__default.warnOnce("Parsley's pubsub module is deprecated; use the 'on' and 'off' methods on parsley instances or window.Parsley");
|
2101
2160
|
};
|
2102
2161
|
|
2103
2162
|
// Returns an event handler that calls `fn` with the arguments it expects
|
@@ -2136,7 +2195,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
2136
2195
|
|
2137
2196
|
$.listenTo = function (instance, name, fn) {
|
2138
2197
|
deprecated();
|
2139
|
-
if (!(instance instanceof parsley_field) && !(instance instanceof
|
2198
|
+
if (!(instance instanceof parsley_field) && !(instance instanceof Form)) throw new Error('Must give Parsley instance');
|
2140
2199
|
|
2141
2200
|
if ('string' !== typeof name || 'function' !== typeof fn) throw new Error('Wrong parameters');
|
2142
2201
|
|
@@ -2151,7 +2210,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
2151
2210
|
|
2152
2211
|
$.unsubscribeTo = function (instance, name) {
|
2153
2212
|
deprecated();
|
2154
|
-
if (!(instance instanceof parsley_field) && !(instance instanceof
|
2213
|
+
if (!(instance instanceof parsley_field) && !(instance instanceof Form)) throw new Error('Must give Parsley instance');
|
2155
2214
|
instance.off(eventName(name));
|
2156
2215
|
};
|
2157
2216
|
|
@@ -2171,7 +2230,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
2171
2230
|
var _instance;
|
2172
2231
|
|
2173
2232
|
deprecated();
|
2174
|
-
var instanceGiven = instance instanceof parsley_field || instance instanceof
|
2233
|
+
var instanceGiven = instance instanceof parsley_field || instance instanceof Form;
|
2175
2234
|
var args = Array.prototype.slice.call(arguments, instanceGiven ? 2 : 1);
|
2176
2235
|
args.unshift(eventName(name));
|
2177
2236
|
if (!instanceGiven) {
|
@@ -2279,7 +2338,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
2279
2338
|
});
|
2280
2339
|
|
2281
2340
|
window.ParsleyExtend.addAsyncValidator = function () {
|
2282
|
-
|
2341
|
+
Utils.warnOnce('Accessing the method `addAsyncValidator` through an instance is deprecated. Simply call `Parsley.addAsyncValidator(...)`');
|
2283
2342
|
return Parsley.addAsyncValidator.apply(Parsley, arguments);
|
2284
2343
|
};
|
2285
2344
|
|