File tree Expand file tree Collapse file tree 5 files changed +15
-50
lines changed Expand file tree Collapse file tree 5 files changed +15
-50
lines changed Original file line number Diff line number Diff line change 67
67
return this . insert ( val , $input , 'left' ) ;
68
68
} ,
69
69
numberFormat : function ( val , $input ) {
70
+ if ( val . length === 0 ) {
71
+ return val ;
72
+ }
70
73
if ( 'numeral' in window ) {
71
74
//If this has been previously formatted, it needs to be unformatted first before being reformatted.
72
75
//Else numeral will fail
73
76
val = numeral ( ) . unformat ( val ) ;
74
77
val = numeral ( val ) . format ( $input . attr ( 'data-sanitize-number-format' ) ) ;
75
78
}
76
79
else {
77
- throw new Error ( 'Using sanitation function "numberFormat" requires that you include numeral.js ' +
80
+ throw new ReferenceError ( 'Using sanitation function "numberFormat" requires that you include numeral.js ' +
78
81
'(http://numeraljs.com/)' ) ;
79
82
}
80
83
return val ;
Original file line number Diff line number Diff line change 166
166
allowsSteps = false ;
167
167
168
168
var sanitize = $el . attr ( 'data-sanitize' ) || '' ;
169
- var isFormattedWithNumeral = sanitize . split ( / \s / ) . find ( function ( name ) {
170
- return ( name === 'numberFormat' ) ;
171
- } ) ;
169
+ var isFormattedWithNumeral = sanitize . match ( / ( ^ | [ \s ] ) n u m b e r F o r m a t ( [ \s ] | $ ) / i) ;
172
170
if ( isFormattedWithNumeral ) {
173
171
if ( ! window . numeral ) {
174
172
throw new ReferenceError ( 'The data-sanitize value numberFormat cannot be used without the numeral' +
175
173
' library. Please see Data Validation in http://www.formvalidator.net for more information.' ) ;
176
174
}
177
175
//Unformat input first, then convert back to String
178
- val = String ( numeral ( ) . unformat ( val ) ) ;
176
+ if ( val . length ) {
177
+ val = String ( numeral ( ) . unformat ( val ) ) ;
178
+ }
179
179
}
180
180
181
181
if ( allowing . indexOf ( 'number' ) === - 1 ) {
Original file line number Diff line number Diff line change 264
264
< label class ="control-label "> Confirm e-mail</ label >
265
265
< input name ="test " data-validation ="confirmation " data-validation-confirm ="testmail " />
266
266
</ div >
267
- < div class ="form-group ">
267
+ < div class ="form-group ">
268
+ <!-- The numeral library appears to not parse correctly when periods are the thousands delimiter
269
+ and commas are the decimal delimiter. -->
268
270
< label class ="control-label "> Number auto formatted '0,0.0000'</ label >
269
271
< input name ="numeral " data-sanitize ="numberFormat " data-sanitize-number-format ="0,0.0000 " />
270
- < label class ="control-label "> Number format with numeral</ label >
272
+ </ div >
273
+ < div class ="form-group ">
274
+ < label class ="control-label "> Number format '0,0.0'</ label >
271
275
< input type ="text " name ="amount " data-validation ="number " data-validation-allowing ="float "
272
- data-sanitize ="numberFormat " data-sanitize-number-format ="0.0, 0 ">
276
+ data-sanitize ="numberFormat " data-sanitize-number-format ="0,0. 0 ">
273
277
</ div >
274
278
< div class ="form-group ">
275
279
< label class ="control-label "> Alphanumeric (will only be validated if the checkbox is checked)</ label >
@@ -454,24 +458,6 @@ <h2>Validation Module: Brazil</h2>
454
458
console . log ( 'Input ' + this . name + ' is ' + validationResult ) ;
455
459
} ) ;
456
460
457
- //Initialize numeral with the correct delimiters for the numberFormat sanitizer
458
- numeral . language ( 'it' , {
459
- delimiters : {
460
- thousands : '.' ,
461
- decimal : ','
462
- } ,
463
- abbreviations : {
464
- thousand : 'k' ,
465
- million : 'm' ,
466
- billion : 'b' ,
467
- trillion : 't'
468
- } ,
469
- currency : {
470
- symbol : '€'
471
- }
472
- } ) ;
473
- numeral . language ( 'it' ) ;
474
-
475
461
} ) ( jQuery , window ) ;
476
462
</ script >
477
463
</ body >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11
11
< div id ="qunit-fixture "> </ div >
12
12
< form id ="dummy-form " style ="visibility: hidden "> </ form >
13
13
14
- < script src ="phantom-polyfills.js "> </ script >
15
14
< script src ="../node_modules/jquery/dist/jquery.min.js "> </ script >
16
15
< script src ="../node_modules/qunitjs/qunit/qunit.js "> </ script >
17
16
< script src ="../form-validator/jquery.form-validator.min.js "> </ script >
You can’t perform that action at this time.
0 commit comments