@@ -100,15 +100,15 @@ export default Base.extend({
100
100
} ,
101
101
// Input is a unix timestamp
102
102
format : function ( value , options ) {
103
- var format = options . dateOnly ? "YYYY-MM-DD" : "YYYY-MM-DD hh:mm:ss" ;
103
+ const format = options . dateOnly ? "YYYY-MM-DD" : "YYYY-MM-DD hh:mm:ss" ;
104
104
return Moment . utc ( value ) . format ( format ) ;
105
105
} ,
106
106
} ) ;
107
107
} ,
108
108
109
- getFieldType : function ( input ) {
110
- var opts = parser . parse ( $ ( input ) ) ;
111
- var type = input . getAttribute ( "type" ) ;
109
+ getFieldType ( input ) {
110
+ const opts = parser . parse ( $ ( input ) ) ;
111
+ let type = input . getAttribute ( "type" ) ;
112
112
if ( _ . contains ( [ "datetime" , "date" ] , opts . type ) ) {
113
113
type = opts . type ;
114
114
}
@@ -118,33 +118,33 @@ export default Base.extend({
118
118
return type ;
119
119
} ,
120
120
121
- setLocalDateConstraints : function ( input , opts , constraints ) {
121
+ setLocalDateConstraints ( input , opts , constraints ) {
122
122
/* Set the relative date constraints, i.e. not-after and not-before, as well as custom messages.
123
123
*/
124
- var name = input . getAttribute ( "name" ) . replace ( / \. / g, "\\." ) ;
125
- var type = this . getFieldType ( input ) ;
126
- var c = constraints [ name ] [ type ] ;
124
+ const name = input . getAttribute ( "name" ) . replace ( / \. / g, "\\." ) ;
125
+ const type = this . getFieldType ( input ) ;
126
+ const c = constraints [ name ] [ type ] ;
127
127
128
128
if ( ! c || typeof opts == "undefined" ) {
129
129
return constraints ;
130
130
}
131
131
132
132
_ . each ( [ "before" , "after" ] , function ( relation ) {
133
- var relative = opts . not ? opts . not [ relation ] : undefined ;
134
- var $ref ;
133
+ const relative = opts . not ? opts . not [ relation ] : undefined ;
135
134
if ( typeof relative === "undefined" ) {
136
135
return ;
137
136
}
138
- var relative_constraint = relation === "before" ? "earliest" : "latest" ;
137
+ const relative_constraint = relation === "before" ? "earliest" : "latest" ;
139
138
if ( Validate . moment . isDate ( relative ) ) {
140
139
c [ relative_constraint ] = relative ;
141
140
} else {
141
+ let $ref ;
142
142
try {
143
143
$ref = $ ( relative ) ;
144
144
} catch ( e ) {
145
145
console . log ( e ) ;
146
146
}
147
- var arr = $ref . data ( "pat-validation-refs" ) || [ ] ;
147
+ const arr = $ref . data ( "pat-validation-refs" ) || [ ] ;
148
148
if ( ! _ . contains ( arr , input ) ) {
149
149
arr . unshift ( input ) ;
150
150
$ref . data ( "pat-validation-refs" , arr ) ;
@@ -158,29 +158,26 @@ export default Base.extend({
158
158
return constraints ;
159
159
} ,
160
160
161
- setLocalConstraints : function ( input , constraints ) {
161
+ setLocalConstraints ( input , constraints ) {
162
162
/* Some form fields might have their own data-pat-validation
163
163
* attribute, used to set field-specific constraints.
164
164
*
165
165
* We parse them and add them to the passed in constraints obj.
166
166
*/
167
- var name = input . getAttribute ( "name" ) . replace ( / \. / g, "\\." ) ,
168
- type = this . getFieldType ( input ) ,
169
- opts = parser . parse ( $ ( input ) ) ,
170
- constraint = constraints [ name ] ;
167
+ const name = input . getAttribute ( "name" ) . replace ( / \. / g, "\\." ) ;
168
+ const type = this . getFieldType ( input ) ;
169
+ const opts = parser . parse ( $ ( input ) ) ;
170
+ let constraint = constraints [ name ] ;
171
171
if ( _ . contains ( [ "datetime" , "date" ] , type ) ) {
172
172
constraints = this . setLocalDateConstraints ( input , opts , constraints ) ;
173
173
} else if ( type == "number" ) {
174
174
_ . each ( [ "min" , "max" ] , function ( limit ) {
175
175
// TODO: need to figure out how to add local validation
176
176
// messages for numericality operators
177
177
if ( input . getAttribute ( limit ) ) {
178
- var constraint = constraints [ name ] ,
179
- key =
180
- limit == "min"
181
- ? "greaterThanOrEqualTo"
182
- : "lessThanOrEqualTo" ,
183
- value = Number ( input . getAttribute ( limit ) ) ;
178
+ const key =
179
+ limit == "min" ? "greaterThanOrEqualTo" : "lessThanOrEqualTo" ;
180
+ const value = Number ( input . getAttribute ( limit ) ) ;
184
181
if ( typeof constraint . numericality === "boolean" ) {
185
182
constraint . numericality = { } ;
186
183
}
@@ -209,7 +206,7 @@ export default Base.extend({
209
206
210
207
// Set local validation messages.
211
208
_ . each ( Object . keys ( VALIDATION_TYPE_MAP ) , function ( type ) {
212
- var c = constraints [ name ] [ VALIDATION_TYPE_MAP [ type ] ] ;
209
+ let c = constraints [ name ] [ VALIDATION_TYPE_MAP [ type ] ] ;
213
210
if ( c === false ) {
214
211
c = { message : "^" + opts . message [ type ] } ;
215
212
} else {
@@ -219,11 +216,11 @@ export default Base.extend({
219
216
return constraints ;
220
217
} ,
221
218
222
- getConstraints : function ( input ) {
219
+ getConstraints ( input ) {
223
220
// Get validation constraints by parsing the input element for hints
224
- var name = input . getAttribute ( "name" ) ,
225
- type = this . getFieldType ( input ) ,
226
- constraints = { } ;
221
+ const name = input . getAttribute ( "name" ) ;
222
+ const type = this . getFieldType ( input ) ;
223
+ const constraints = { } ;
227
224
if ( ! name ) {
228
225
return ;
229
226
}
@@ -246,18 +243,17 @@ export default Base.extend({
246
243
? { message : "^" + this . options . message . date }
247
244
: false ,
248
245
} ;
249
- constraints = this . setLocalConstraints ( input , constraints ) ;
250
- return constraints ;
246
+ return this . setLocalConstraints ( input , constraints ) ;
251
247
} ,
252
248
253
- doDateCheck : function ( input ) {
249
+ doDateCheck ( input ) {
254
250
// Returns true if a date check should be done.
255
251
// Don't check if there is no input - this should be handled by
256
252
// the ``required`` attribute.
257
253
// In case of HTML5 date/datetime-local support we also have to
258
254
// check for ``badInput`` as invalid date input will result in an
259
255
// empty ``value``.
260
- var type = input . getAttribute ( "type" ) ; // we need the raw type here
256
+ const type = input . getAttribute ( "type" ) ; // we need the raw type here
261
257
if (
262
258
utils . checkInputSupport ( "date" , "wrong value" ) &&
263
259
type . indexOf ( "date" ) === 0 &&
@@ -273,13 +269,13 @@ export default Base.extend({
273
269
}
274
270
} ,
275
271
276
- getValueDict : function ( input ) {
272
+ getValueDict ( input ) {
277
273
/* Return a dict {name: value} derived from a DOM input element.
278
274
* Used by validate.js's validate method.
279
275
*/
280
- var value_dict = { } ;
281
- var name = input . getAttribute ( "name" ) ;
282
- var value = input . value ;
276
+ const value_dict = { } ;
277
+ const name = input . getAttribute ( "name" ) ;
278
+ let value = input . value ;
283
279
if ( input . getAttribute ( "type" ) == "number" ) {
284
280
if ( value !== "" ) {
285
281
try {
@@ -295,23 +291,23 @@ export default Base.extend({
295
291
return value_dict ;
296
292
} ,
297
293
298
- validateForm : function ( ev ) {
294
+ validateForm ( ev ) {
299
295
/* Handler which gets called when the entire form needs to be
300
296
* validated. Will prevent the event's default action if validation fails.
301
297
*/
302
- var has_errors = false ;
298
+ let has_errors = false ;
303
299
// Ignore invisible elements (otherwise pat-clone template
304
300
// elements get validated). Not aware of other cases where this
305
301
// might cause problems.
306
- var $single = this . $inputs . filter (
302
+ const $single = this . $inputs . filter (
307
303
":visible:enabled:not(:checkbox):not(:radio), .pat-autosuggest:not(:visible)"
308
304
) ;
309
- var group_names = this . $inputs
305
+ const group_names = this . $inputs
310
306
. filter ( ":enabled:checkbox, :enabled:radio" )
311
307
. map ( function ( ) {
312
308
return this . getAttribute ( "name" ) ;
313
309
} ) ;
314
- var handleError = function ( error ) {
310
+ const handleError = function ( error ) {
315
311
if ( typeof error != "undefined" ) {
316
312
if ( ! has_errors && ev ) {
317
313
ev . preventDefault ( ) ;
@@ -332,13 +328,13 @@ export default Base.extend({
332
328
}
333
329
} ,
334
330
335
- customizeMessage : function ( msg , input ) {
331
+ customizeMessage ( msg , input ) {
336
332
/* Due to a limitation in validate.js, whereby we cannot have more
337
333
* fine-grained error messages for sub-validations (e.g. is a
338
334
* number and is bigger than 5), we need to customize the messages
339
335
* after validation. We do that here.
340
336
*/
341
- var opts = parser . parse ( $ ( input ) ) ;
337
+ const opts = parser . parse ( $ ( input ) ) ;
342
338
if ( msg . indexOf ( "must be greater than or equal to" ) != - 1 ) {
343
339
return Validate . format ( opts . message . min , {
344
340
count : input . getAttribute ( "min" ) ,
@@ -355,10 +351,10 @@ export default Base.extend({
355
351
return msg ;
356
352
} ,
357
353
358
- validateGroupedElement : function ( name ) {
354
+ validateGroupedElement ( name ) {
359
355
/* Handler which gets called for :checkbox and :radio elments. */
360
- var input = this . $el . find ( '[name="' + name + '"]' ) [ 0 ] ;
361
- var error = Validate (
356
+ const input = this . $el . find ( '[name="' + name + '"]' ) [ 0 ] ;
357
+ const error = Validate (
362
358
_ . pick ( Validate . collectFormValues ( this . $el ) , name ) ,
363
359
this . getConstraints ( input )
364
360
) ;
@@ -375,19 +371,19 @@ export default Base.extend({
375
371
return error ;
376
372
} ,
377
373
378
- validateElement : function ( input , no_recurse ) {
374
+ validateElement ( input , no_recurse ) {
379
375
/* Handler which gets called when a single form input element
380
376
* needs to be validated. Will prevent the event's default action
381
377
* if validation fails.
382
378
*/
383
379
if ( input . disabled ) {
384
380
return ;
385
381
}
386
- var error = Validate ( this . getValueDict ( input ) , this . getConstraints ( input ) ) ;
382
+ const error = Validate ( this . getValueDict ( input ) , this . getConstraints ( input ) ) ;
387
383
if ( ! error ) {
388
384
this . removeError ( input ) ;
389
385
} else {
390
- var name = input . getAttribute ( "name" ) . replace ( / \. / g, "\\." ) ;
386
+ const name = input . getAttribute ( "name" ) . replace ( / \. / g, "\\." ) ;
391
387
_ . each (
392
388
error [ name ] ,
393
389
function ( msg ) {
@@ -404,7 +400,7 @@ export default Base.extend({
404
400
return error ;
405
401
} ,
406
402
407
- onPatternUpdate : function ( ev , data ) {
403
+ onPatternUpdate ( ev , data ) {
408
404
/* Handler which gets called when pat-update is triggered within
409
405
* the .pat-validation element.
410
406
*
@@ -424,19 +420,21 @@ export default Base.extend({
424
420
return true ;
425
421
} ,
426
422
427
- findErrorMessages : function ( el ) {
428
- var $el = $ ( el ) ,
429
- selector = "em.validation.message" ,
430
- $messages = $el . next ( selector ) ;
423
+ findErrorMessages ( el ) {
424
+ const $el = $ ( el ) ;
425
+ const selector = "em.validation.message" ;
426
+ let $messages = $el . next ( selector ) ;
431
427
if ( $el . is ( "[type=radio],[type=checkbox]" ) ) {
432
- var $fieldset = $el . closest ( "fieldset.pat-checklist" ) ;
433
- if ( $fieldset . length ) $messages = $fieldset . find ( selector ) ;
428
+ const $fieldset = $el . closest ( "fieldset.pat-checklist" ) ;
429
+ if ( $fieldset . length ) {
430
+ $messages = $fieldset . find ( selector ) ;
431
+ }
434
432
}
435
433
return $messages ;
436
434
} ,
437
435
438
- removeError : function ( input ) {
439
- var $errors = this . findErrorMessages ( input ) ;
436
+ removeError ( input ) {
437
+ const $errors = this . findErrorMessages ( input ) ;
440
438
this . errors = this . errors - $errors . length ;
441
439
$errors . remove ( ) ;
442
440
utils . findRelatives ( input ) . removeClass ( "is-invalid" ) . addClass ( "is-valid" ) ;
@@ -447,15 +445,14 @@ export default Base.extend({
447
445
}
448
446
} ,
449
447
450
- showError : function ( error , input ) {
451
- var $el = $ ( input ) ,
452
- $relatives = utils . findRelatives ( input ) ,
453
- $position = $el ,
454
- strategy = "after" ,
455
- $message = $ ( "<em/>" , { class : "validation warning message" } ) ,
456
- $fieldset ;
448
+ showError ( error , input ) {
449
+ const $el = $ ( input ) ;
450
+ const $relatives = utils . findRelatives ( input ) ;
451
+ let $position = $el ;
452
+ let strategy = "after" ;
453
+ const $message = $ ( "<em/>" , { class : "validation warning message" } ) ;
457
454
if ( $el . is ( "[type=radio],[type=checkbox]" ) ) {
458
- $fieldset = $el . closest ( "fieldset.pat-checklist" ) ;
455
+ const $fieldset = $el . closest ( "fieldset.pat-checklist" ) ;
459
456
if ( $fieldset . length ) {
460
457
$position = $fieldset ;
461
458
strategy = "append" ;
0 commit comments