Skip to content

Commit 7c8873d

Browse files
committed
Fix react component value change issue
1 parent 35d2e1d commit 7c8873d

File tree

10 files changed

+31
-15
lines changed

10 files changed

+31
-15
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,18 @@ require('cleave.js/dist/addons/cleave-phone.{country}');
7878
var cleave = new Cleave(...)
7979
```
8080

81-
We don't want to register any transfer tool as dependencies, so for **Browserify** users, please also run this:
81+
For **Browserify** users, please also run this:
8282

8383
```bash
8484
npm install --save babelify browserify-shim
8585
```
8686

87+
And add this empty `browserify-shim` config to your package.json:
88+
```js
89+
"browserify-shim": {
90+
}
91+
```
92+
8793
#### AMD
8894

8995
```js

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"form",
99
"input"
1010
],
11-
"version": "0.6.3",
11+
"version": "0.6.5",
1212
"author": {
1313
"name": "Max Huang",
1414
"email": "[email protected]",

dist/cleave-react.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ return /******/ (function(modules) { // webpackBootstrap
8282
newValue = nextProps.value;
8383

8484
if (newValue) {
85-
owner.onInput(newValue);
85+
newValue = newValue.toString();
86+
87+
if (newValue !== owner.properties.initValue) {
88+
owner.properties.initValue = newValue;
89+
owner.onInput(newValue);
90+
}
8691
}
8792

8893
// update phone region code

dist/cleave-react.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cleave.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ Cleave.prototype = {
235235
setRawValue: function (value) {
236236
var owner = this;
237237

238+
value = value.toString();
239+
238240
owner.element.value = value;
239241
owner.onInput(value);
240242
},

dist/cleave.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/reactjs-component-usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ npm install --save babel-preset-es2015 babel-preset-react babel-preset-stage-0
2121
For `Browserify`, also do:
2222

2323
```bash
24-
npm install --save babelify
24+
npm install --save babelify browserify-shim
2525
```
2626

2727
For `Webpack`, also do:
@@ -30,7 +30,7 @@ For `Webpack`, also do:
3030
npm install --save babel-core babel-loader
3131
```
3232

33-
Second, add `.babelrc` to your project root:
33+
After that, add `.babelrc` to your project root with:
3434

3535
```json
3636
{

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"form",
1111
"input"
1212
],
13-
"version": "0.6.3",
13+
"version": "0.6.5",
1414
"author": {
1515
"name": "Max Huang",
1616
"url": "http://github.com/nosir",
@@ -28,10 +28,6 @@
2828
"scripts": {
2929
"test": "gulp test"
3030
},
31-
"browserify-shim": {
32-
"react": "global:React",
33-
"react-dom": "global:ReactDOM"
34-
},
3531
"browserify": {
3632
"transform": [
3733
"babelify",

src/Cleave.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ Cleave.prototype = {
233233
setRawValue: function (value) {
234234
var owner = this;
235235

236+
value = value.toString();
237+
236238
owner.element.value = value;
237239
owner.onInput(value);
238240
},

src/Cleave.react.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ var Cleave = React.createClass({
2020
newValue = nextProps.value;
2121

2222
if (newValue) {
23-
owner.onInput(newValue);
23+
newValue = newValue.toString();
24+
25+
if (newValue !== owner.properties.initValue) {
26+
owner.properties.initValue = newValue;
27+
owner.onInput(newValue);
28+
}
2429
}
2530

2631
// update phone region code

0 commit comments

Comments
 (0)