Skip to content
Open
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
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
11 changes: 7 additions & 4 deletions jquery.priceformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
var insertPlusSign = options.insertPlusSign;
var clearOnEmpty = options.clearOnEmpty;
var leadingZero = options.leadingZero;
var allowZero = options.allowZero;

// If insertPlusSign is on, it automatic turns on allowNegative, to work with Signs
if (insertPlusSign) allowNegative = true;
Expand Down Expand Up @@ -111,8 +112,9 @@

// format as price
function price_format(str, ignore) {
if (!ignore && (str === '' || str == price_format('0', true)) && clearOnEmpty)
return '';
if (!ignore && (str === "" || (str === price_format("0", true) && !allowZero)) && clearOnEmpty) {
return "";
}

// formatting settings
var formatted = fill_with_zeroes(to_numbers(str));
Expand Down Expand Up @@ -233,7 +235,7 @@
var price = price_format(str);
if (str != price) set(price);
var format = price_format('0', true);
if (price == format && str != '0' && clearOnEmpty) set('');
if (price == format && str != '0' && clearOnEmpty && !allowZero) set('');
}

// Add prefix on focus
Expand Down Expand Up @@ -356,6 +358,7 @@
allowNegative: false,
insertPlusSign: false,
clearOnEmpty: false,
leadingZero: true
leadingZero: true,
allowZero: false
};
}));
2 changes: 1 addition & 1 deletion jquery.priceformat.min.js

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

6 changes: 4 additions & 2 deletions prototype.priceformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ NumberFormat = Class.create( {
centsLimit : 2,
clearPrefix : false,
allowNegative : false,
clearOnEmpty: false
clearOnEmpty: false,
allowZero: false
}, options);

this.is_number = /[0-9]/;
Expand All @@ -24,6 +25,7 @@ NumberFormat = Class.create( {
this.clearPrefix = options.clearPrefix;
this.allowNegative = options.allowNegative;
this.clearOnEmpty = options.clearOnEmpty;
this.allowZero = options.allowZero;
if (this.clearPrefix) {
Event.observe(this.el, 'blur', this.clearPrefix.bind(this));
Event.observe(this.el, 'focus', this.addPrefix.bind(this));
Expand Down Expand Up @@ -127,7 +129,7 @@ NumberFormat = Class.create( {
},

priceFormat : function(str, ignore) {
if(!ignore && (str === '' || str == this.priceFormat('0', true)) && clearOnEmpty) {
if(!ignore && (str === '' || (str == this.priceFormat('0', true) && !allowZero)) && clearOnEmpty) {

return '';
}
Expand Down
2 changes: 1 addition & 1 deletion prototype.priceformat.min.js

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