Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: strict positive number #660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description":
"JavaScript library for formatting input text content when you are typing",
"keywords": ["cleave", "javascript", "html", "form", "input"],
"version": "1.6.0",
"version": "1.6.1",
"author": {
"name": "Max Huang",
"email": "[email protected]",
Expand Down
22 changes: 20 additions & 2 deletions dist/cleave-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ return /******/ (function(modules) { // webpackBootstrap
* @param {String | HTMLElement} element
* @param {Object} opts
*/

var Cleave = function (element, opts) {
var owner = this;
var hasMultipleElements = false;
Expand Down Expand Up @@ -116,6 +117,7 @@ return /******/ (function(modules) { // webpackBootstrap
owner.isBackward = '';

owner.onChangeListener = owner.onChange.bind(owner);
owner.onBlurListener = owner.onBlur.bind(owner);
owner.onKeyDownListener = owner.onKeyDown.bind(owner);
owner.onFocusListener = owner.onFocus.bind(owner);
owner.onCutListener = owner.onCut.bind(owner);
Expand All @@ -124,6 +126,7 @@ return /******/ (function(modules) { // webpackBootstrap
owner.initSwapHiddenInput();

owner.element.addEventListener('input', owner.onChangeListener);
owner.element.addEventListener('blur', owner.onBlurListener );
owner.element.addEventListener('keydown', owner.onKeyDownListener);
owner.element.addEventListener('focus', owner.onFocusListener);
owner.element.addEventListener('cut', owner.onCutListener);
Expand Down Expand Up @@ -395,6 +398,20 @@ return /******/ (function(modules) { // webpackBootstrap
owner.updateValueState();
},

onBlur: function () {
var owner = this, pps = owner.properties,
value = parseFloat(owner.getRawValue());

// numeral formatter
if (pps.numeral && (isNaN(value) // if `.` only entered
|| (pps.numeralPositiveOnly === 'strict' && value === 0))) {
pps.result = '';
owner.updateValueState();

return;
}
},

updateCreditCardPropsByValue: function (value) {
var owner = this, pps = owner.properties,
Util = Cleave.Util,
Expand Down Expand Up @@ -530,6 +547,7 @@ return /******/ (function(modules) { // webpackBootstrap
var owner = this;

owner.element.removeEventListener('input', owner.onChangeListener);
owner.element.removeEventListener('blur', owner.onBlurListener);
owner.element.removeEventListener('keydown', owner.onKeyDownListener);
owner.element.removeEventListener('focus', owner.onFocusListener);
owner.element.removeEventListener('cut', owner.onCutListener);
Expand Down Expand Up @@ -1667,14 +1685,14 @@ return /******/ (function(modules) { // webpackBootstrap
target.numeralDecimalScale = opts.numeralDecimalScale >= 0 ? opts.numeralDecimalScale : 2;
target.numeralDecimalMark = opts.numeralDecimalMark || '.';
target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand';
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
target.numeralPositiveOnly = opts.numeralPositiveOnly;
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
target.signBeforePrefix = !!opts.signBeforePrefix;
target.tailPrefix = !!opts.tailPrefix;

// others
target.swapHiddenInput = !!opts.swapHiddenInput;

target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

target.uppercase = !!opts.uppercase;
Expand Down
6 changes: 3 additions & 3 deletions dist/cleave-angular.min.js

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions dist/cleave-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,14 +1005,14 @@ var DefaultProperties = {
target.numeralDecimalScale = opts.numeralDecimalScale >= 0 ? opts.numeralDecimalScale : 2;
target.numeralDecimalMark = opts.numeralDecimalMark || '.';
target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand';
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
target.numeralPositiveOnly = opts.numeralPositiveOnly;
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
target.signBeforePrefix = !!opts.signBeforePrefix;
target.tailPrefix = !!opts.tailPrefix;

// others
target.swapHiddenInput = !!opts.swapHiddenInput;

target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

target.uppercase = !!opts.uppercase;
Expand Down Expand Up @@ -1062,6 +1062,7 @@ var DefaultProperties_1 = DefaultProperties;
* @param {String | HTMLElement} element
* @param {Object} opts
*/

var Cleave = function (element, opts) {
var owner = this;
var hasMultipleElements = false;
Expand Down Expand Up @@ -1116,6 +1117,7 @@ Cleave.prototype = {
owner.isBackward = '';

owner.onChangeListener = owner.onChange.bind(owner);
owner.onBlurListener = owner.onBlur.bind(owner);
owner.onKeyDownListener = owner.onKeyDown.bind(owner);
owner.onFocusListener = owner.onFocus.bind(owner);
owner.onCutListener = owner.onCut.bind(owner);
Expand All @@ -1124,6 +1126,7 @@ Cleave.prototype = {
owner.initSwapHiddenInput();

owner.element.addEventListener('input', owner.onChangeListener);
owner.element.addEventListener('blur', owner.onBlurListener );
owner.element.addEventListener('keydown', owner.onKeyDownListener);
owner.element.addEventListener('focus', owner.onFocusListener);
owner.element.addEventListener('cut', owner.onCutListener);
Expand Down Expand Up @@ -1395,6 +1398,20 @@ Cleave.prototype = {
owner.updateValueState();
},

onBlur: function () {
var owner = this, pps = owner.properties,
value = parseFloat(owner.getRawValue());

// numeral formatter
if (pps.numeral && (isNaN(value) // if `.` only entered
|| (pps.numeralPositiveOnly === 'strict' && value === 0))) {
pps.result = '';
owner.updateValueState();

return;
}
},

updateCreditCardPropsByValue: function (value) {
var owner = this, pps = owner.properties,
Util = Cleave.Util,
Expand Down Expand Up @@ -1530,6 +1547,7 @@ Cleave.prototype = {
var owner = this;

owner.element.removeEventListener('input', owner.onChangeListener);
owner.element.removeEventListener('blur', owner.onBlurListener);
owner.element.removeEventListener('keydown', owner.onKeyDownListener);
owner.element.removeEventListener('focus', owner.onFocusListener);
owner.element.removeEventListener('cut', owner.onCutListener);
Expand Down
2 changes: 1 addition & 1 deletion dist/cleave-esm.min.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions dist/cleave-react-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,14 @@ return /******/ (function(modules) { // webpackBootstrap

onBlur: function onBlur(event) {
var owner = this,
pps = owner.properties;
pps = owner.properties,
value = parseFloat(owner.getRawValue());

// numeral formatter
if (pps.numeral && (isNaN(value) // if `.` only entered
|| pps.numeralPositiveOnly === 'strict' && value === 0)) {
pps.result = '';
}

event.target.rawValue = owner.getRawValue();
event.target.value = pps.result;
Expand Down Expand Up @@ -2840,7 +2847,7 @@ return /******/ (function(modules) { // webpackBootstrap
target.numeralDecimalScale = opts.numeralDecimalScale >= 0 ? opts.numeralDecimalScale : 2;
target.numeralDecimalMark = opts.numeralDecimalMark || '.';
target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand';
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
target.numeralPositiveOnly = opts.numeralPositiveOnly;
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
target.signBeforePrefix = !!opts.signBeforePrefix;
target.tailPrefix = !!opts.tailPrefix;
Expand Down
7 changes: 4 additions & 3 deletions dist/cleave-react-node.min.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions dist/cleave-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,14 @@ return /******/ (function(modules) { // webpackBootstrap

onBlur: function onBlur(event) {
var owner = this,
pps = owner.properties;
pps = owner.properties,
value = parseFloat(owner.getRawValue());

// numeral formatter
if (pps.numeral && (isNaN(value) // if `.` only entered
|| pps.numeralPositiveOnly === 'strict' && value === 0)) {
pps.result = '';
}

event.target.rawValue = owner.getRawValue();
event.target.value = pps.result;
Expand Down Expand Up @@ -3034,7 +3041,7 @@ return /******/ (function(modules) { // webpackBootstrap
target.numeralDecimalScale = opts.numeralDecimalScale >= 0 ? opts.numeralDecimalScale : 2;
target.numeralDecimalMark = opts.numeralDecimalMark || '.';
target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand';
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
target.numeralPositiveOnly = opts.numeralPositiveOnly;
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
target.signBeforePrefix = !!opts.signBeforePrefix;
target.tailPrefix = !!opts.tailPrefix;
Expand Down
8 changes: 4 additions & 4 deletions dist/cleave-react.min.js

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions dist/cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ return /******/ (function(modules) { // webpackBootstrap
* @param {String | HTMLElement} element
* @param {Object} opts
*/

var Cleave = function (element, opts) {
var owner = this;
var hasMultipleElements = false;
Expand Down Expand Up @@ -116,6 +117,7 @@ return /******/ (function(modules) { // webpackBootstrap
owner.isBackward = '';

owner.onChangeListener = owner.onChange.bind(owner);
owner.onBlurListener = owner.onBlur.bind(owner);
owner.onKeyDownListener = owner.onKeyDown.bind(owner);
owner.onFocusListener = owner.onFocus.bind(owner);
owner.onCutListener = owner.onCut.bind(owner);
Expand All @@ -124,6 +126,7 @@ return /******/ (function(modules) { // webpackBootstrap
owner.initSwapHiddenInput();

owner.element.addEventListener('input', owner.onChangeListener);
owner.element.addEventListener('blur', owner.onBlurListener );
owner.element.addEventListener('keydown', owner.onKeyDownListener);
owner.element.addEventListener('focus', owner.onFocusListener);
owner.element.addEventListener('cut', owner.onCutListener);
Expand Down Expand Up @@ -395,6 +398,20 @@ return /******/ (function(modules) { // webpackBootstrap
owner.updateValueState();
},

onBlur: function () {
var owner = this, pps = owner.properties,
value = parseFloat(owner.getRawValue());

// numeral formatter
if (pps.numeral && (isNaN(value) // if `.` only entered
|| (pps.numeralPositiveOnly === 'strict' && value === 0))) {
pps.result = '';
owner.updateValueState();

return;
}
},

updateCreditCardPropsByValue: function (value) {
var owner = this, pps = owner.properties,
Util = Cleave.Util,
Expand Down Expand Up @@ -530,6 +547,7 @@ return /******/ (function(modules) { // webpackBootstrap
var owner = this;

owner.element.removeEventListener('input', owner.onChangeListener);
owner.element.removeEventListener('blur', owner.onBlurListener);
owner.element.removeEventListener('keydown', owner.onKeyDownListener);
owner.element.removeEventListener('focus', owner.onFocusListener);
owner.element.removeEventListener('cut', owner.onCutListener);
Expand Down Expand Up @@ -1610,14 +1628,14 @@ return /******/ (function(modules) { // webpackBootstrap
target.numeralDecimalScale = opts.numeralDecimalScale >= 0 ? opts.numeralDecimalScale : 2;
target.numeralDecimalMark = opts.numeralDecimalMark || '.';
target.numeralThousandsGroupStyle = opts.numeralThousandsGroupStyle || 'thousand';
target.numeralPositiveOnly = !!opts.numeralPositiveOnly;
target.numeralPositiveOnly = opts.numeralPositiveOnly;
target.stripLeadingZeroes = opts.stripLeadingZeroes !== false;
target.signBeforePrefix = !!opts.signBeforePrefix;
target.tailPrefix = !!opts.tailPrefix;

// others
target.swapHiddenInput = !!opts.swapHiddenInput;

target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

target.uppercase = !!opts.uppercase;
Expand Down
6 changes: 3 additions & 3 deletions dist/cleave.min.js

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion doc/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ new Cleave('.my-input', {

### `numeralPositiveOnly`

A `Boolean` value indicates if it only allows positive numeral value
A `Boolean` or `String` value indicates if it only allows positive numeral value

For `String` type, only the word `strict` in lowercase is available to indicate even `zero (0)` is not acceptable.

**Default value**: `false`

Expand All @@ -351,9 +353,22 @@ new Cleave('.my-input', {
```

```js
// -1234.56 entered
// 1234.56
```

```js
new Cleave('.my-input', {
numeral: true,
numeralPositiveOnly: 'strict'
});
```

```js
// `zero` (-0.0000) entered
// (blank)
```

### `signBeforePrefix`

A `Boolean` value indicates if the sign of the numeral should appear before the prefix.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"vanilla",
"react"
],
"version": "1.6.0",
"version": "1.6.1",
"files": [
"src",
"dist",
Expand Down
18 changes: 18 additions & 0 deletions src/Cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @param {String | HTMLElement} element
* @param {Object} opts
*/

var Cleave = function (element, opts) {
var owner = this;
var hasMultipleElements = false;
Expand Down Expand Up @@ -60,6 +61,7 @@ Cleave.prototype = {
owner.isBackward = '';

owner.onChangeListener = owner.onChange.bind(owner);
owner.onBlurListener = owner.onBlur.bind(owner);
owner.onKeyDownListener = owner.onKeyDown.bind(owner);
owner.onFocusListener = owner.onFocus.bind(owner);
owner.onCutListener = owner.onCut.bind(owner);
Expand All @@ -68,6 +70,7 @@ Cleave.prototype = {
owner.initSwapHiddenInput();

owner.element.addEventListener('input', owner.onChangeListener);
owner.element.addEventListener('blur', owner.onBlurListener );
owner.element.addEventListener('keydown', owner.onKeyDownListener);
owner.element.addEventListener('focus', owner.onFocusListener);
owner.element.addEventListener('cut', owner.onCutListener);
Expand Down Expand Up @@ -339,6 +342,20 @@ Cleave.prototype = {
owner.updateValueState();
},

onBlur: function () {
var owner = this, pps = owner.properties,
value = parseFloat(owner.getRawValue());

// numeral formatter
if (pps.numeral && (isNaN(value) // if `.` only entered
|| (pps.numeralPositiveOnly === 'strict' && value === 0))) {
pps.result = '';
owner.updateValueState();

return;
}
},

updateCreditCardPropsByValue: function (value) {
var owner = this, pps = owner.properties,
Util = Cleave.Util,
Expand Down Expand Up @@ -474,6 +491,7 @@ Cleave.prototype = {
var owner = this;

owner.element.removeEventListener('input', owner.onChangeListener);
owner.element.removeEventListener('blur', owner.onBlurListener);
owner.element.removeEventListener('keydown', owner.onKeyDownListener);
owner.element.removeEventListener('focus', owner.onFocusListener);
owner.element.removeEventListener('cut', owner.onCutListener);
Expand Down
9 changes: 8 additions & 1 deletion src/Cleave.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,14 @@ var cleaveReactClass = CreateReactClass({
},

onBlur: function (event) {
var owner = this, pps = owner.properties;
var owner = this, pps = owner.properties,
value = parseFloat(owner.getRawValue());

// numeral formatter
if (pps.numeral && (isNaN(value) // if `.` only entered
|| (pps.numeralPositiveOnly === 'strict' && value === 0))) {
pps.result = '';
}

event.target.rawValue = owner.getRawValue();
event.target.value = pps.result;
Expand Down
Loading