Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = function (grunt) {
}
});

// Add options for concat ang ugligy
// Add options for concat and uglify
filesToBuild.concat.options = {
banner: "<%= meta.banner %>"
};
Expand Down Expand Up @@ -174,6 +174,7 @@ module.exports = function (grunt) {

grunt.registerTask("build", ["version", "concat", "uglify"]);
grunt.registerTask('test', ['concat', 'jshint', 'qunit']);
grunt.registerTask('test-uglify', ['concat', 'uglify', 'jshint', 'qunit']);
grunt.registerTask("default", ["test", "build"]);

};
2 changes: 1 addition & 1 deletion form-validator/lang/cz.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license MIT
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/cz.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/lang/de.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license MIT
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/de.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/lang/es.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/lang/fr.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license MIT
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/fr.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/lang/it.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license Dual licensed under the MIT or GPL Version 2 licenses
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/it.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/lang/pl.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license MIT
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/pl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/lang/pt.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license MIT
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/pt.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/lang/ro.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license MIT
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/ro.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/lang/ru.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license MIT
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/ru.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/lang/sv.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @website http://formvalidator.net/
* @license MIT
* @version 2.2.144
* @version 2.2.145
*/
(function($, window) {

Expand Down
2 changes: 1 addition & 1 deletion form-validator/lang/sv.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion form-validator/sanitize.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@
},
numberFormat : function(val, $input) {
if ( 'numeral' in window ) {
//If this has been previously formatted, it needs to be unformatted first before being reformatted.
//Else numeral will fail
val = numeral().unformat(val);
val = numeral(val).format( $input.attr('data-sanitize-number-format') );
}
else {
throw new Error('Using sanitation function "numberFormat" requires that you include numeraljs (http://http://numeraljs.com/)');
throw new Error('Using sanitation function "numberFormat" requires that you include numeral.js ' +
'(http://numeraljs.com/)');
}
return val;
},
Expand Down
13 changes: 13 additions & 0 deletions form-validator/src/core-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@
steps = $el.valAttr('step') || '',
allowsSteps = false;

var sanitize = $el.attr('data-sanitize') || '';
var isFormattedWithNumeral = sanitize.split(/\s/).find(function (name) {
return (name === 'numberFormat');
});
if (isFormattedWithNumeral) {
if (!window.numeral) {
throw new ReferenceError('The data-sanitize value numberFormat cannot be used without the numeral' +
' library. Please see Data Validation in http://www.formvalidator.net for more information.');
}
//Unformat input first, then convert back to String
val = String(numeral().unformat(val));
}

if (allowing.indexOf('number') === -1) {
allowing += ',number';
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"grunt-contrib-uglify": "^0.8.0",
"grunt-contrib-watch": "^0.6.1",
"jquery": "^2.1.4",
"numeral": "~1.5.3",
"qunitjs": "^1.20.0"
},
"dependencies": {
Expand Down
22 changes: 21 additions & 1 deletion test/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@
<div class="form-group">
<label class="control-label">Number auto formatted '0,0.0000'</label>
<input name="numeral" data-sanitize="numberFormat" data-sanitize-number-format="0,0.0000" />
<label class="control-label">Number format with numeral</label>
<input type="text" name="amount" data-validation="number" data-validation-allowing="float"
data-sanitize="numberFormat" data-sanitize-number-format="0.0,0">
</div>
<div class="form-group">
<label class="control-label">Alphanumeric (will only be validated if the checkbox is checked)</label>
Expand Down Expand Up @@ -425,7 +428,6 @@ <h2>Validation Module: Brazil</h2>
window.applyValidation(true, '#form-a', 'top');
window.applyValidation(false, '#form-b', 'element');
window.applyValidation(true, '#form-c', function() {
console.log('in here then');
return $('#error-container');
}, 'sanitize'+dev);
window.applyValidation(true, '#form-d', 'element', 'html5'+dev);
Expand All @@ -450,6 +452,24 @@ <h2>Validation Module: Brazil</h2>
console.log('Input '+this.name+' is '+validationResult);
});

//Initialize numeral with the correct delimiters for the numberFormat sanitizer
numeral.language('it', {
delimiters: {
thousands: '.',
decimal: ','
},
abbreviations: {
thousand: 'k',
million: 'm',
billion: 'b',
trillion: 't'
},
currency: {
symbol: '€'
}
});
numeral.language('it');

})(jQuery, window);
</script>
</body>
Expand Down
23 changes: 23 additions & 0 deletions test/phantom-polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//MDN
if (!Array.prototype.find) {
Array.prototype.find = function(predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;

for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
37 changes: 29 additions & 8 deletions test/qunit.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
<div id="qunit-fixture"></div>
<form id="dummy-form" style="visibility: hidden"></form>

<script src="phantom-polyfills.js"></script>
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../form-validator/jquery.form-validator.min.js"></script>
<script src="../node_modules/numeral/numeral.js"></script>
<script>
(function($) {

Expand Down Expand Up @@ -833,10 +835,27 @@
attr: {
'data-sanitize-strip' : '$, @'
}
}, /* This functionality doesn't work correctly. See issue #381
escape: {
val: '<p style="color: pink">hejsan & så\' vidare</p>',
expected: '&lt;p style=&quot;color: pink&quot;&gt;hejsan &amp; så&#8217; vidare&lt;/p&gt;'
}, */
basicNumberFormat1: {
val: '-8000.00',
expected: '-8,000.0',
attr: {
'data-sanitize-number-format': '0,0.0'
},
sanitize: 'numberFormat'
},
escape : {
val : '<p style="color: pink">hejsan & så\' vidare</p>',
expected: '&lt;p style=&quot;color: pink&quot;&gt;hejsan &amp; så&#8217; vidare&lt;/p&gt;' }
basicNumberFormat2: {
val: '12221.444',
expected: '12,221',
attr: {
'data-sanitize-number-format': '0,0'
},
sanitize: 'numberFormat'
}
};

$.each(sanitationTests, function(sanitation, data) {
Expand All @@ -846,13 +865,15 @@
$input.attr(attrName, attrVal);
});
$.formUtils.setupSanitation({}, $form, $.formUtils.defaultConfig());

$input.val(data.val);

$input.trigger('blur');
equal($input.val(), data.expected, 'Sanitize with "'+sanitation+'"');
//Verify that sanitizing twice has no effect
$input.trigger('focus');
$input.trigger('blur');
equal(
$input.val(),
data.expected,
'Sanitize with "'+sanitation+'"'
);
equal($input.val(), data.expected, 'Sanitize twice with "'+sanitation+'"');
});

});
Expand Down