Skip to content

Commit

Permalink
Fix react component value change issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nosir committed Aug 6, 2016
1 parent 35d2e1d commit 7c8873d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 15 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ require('cleave.js/dist/addons/cleave-phone.{country}');
var cleave = new Cleave(...)
```

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

```bash
npm install --save babelify browserify-shim
```

And add this empty `browserify-shim` config to your package.json:
```js
"browserify-shim": {
}
```

#### AMD

```js
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"form",
"input"
],
"version": "0.6.3",
"version": "0.6.5",
"author": {
"name": "Max Huang",
"email": "[email protected]",
Expand Down
7 changes: 6 additions & 1 deletion dist/cleave-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ return /******/ (function(modules) { // webpackBootstrap
newValue = nextProps.value;

if (newValue) {
owner.onInput(newValue);
newValue = newValue.toString();

if (newValue !== owner.properties.initValue) {
owner.properties.initValue = newValue;
owner.onInput(newValue);
}
}

// update phone region code
Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-react.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ Cleave.prototype = {
setRawValue: function (value) {
var owner = this;

value = value.toString();

owner.element.value = value;
owner.onInput(value);
},
Expand Down
4 changes: 2 additions & 2 deletions dist/cleave.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions doc/reactjs-component-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm install --save babel-preset-es2015 babel-preset-react babel-preset-stage-0
For `Browserify`, also do:

```bash
npm install --save babelify
npm install --save babelify browserify-shim
```

For `Webpack`, also do:
Expand All @@ -30,7 +30,7 @@ For `Webpack`, also do:
npm install --save babel-core babel-loader
```

Second, add `.babelrc` to your project root:
After that, add `.babelrc` to your project root with:

```json
{
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"form",
"input"
],
"version": "0.6.3",
"version": "0.6.5",
"author": {
"name": "Max Huang",
"url": "http://github.com/nosir",
Expand All @@ -28,10 +28,6 @@
"scripts": {
"test": "gulp test"
},
"browserify-shim": {
"react": "global:React",
"react-dom": "global:ReactDOM"
},
"browserify": {
"transform": [
"babelify",
Expand Down
2 changes: 2 additions & 0 deletions src/Cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ Cleave.prototype = {
setRawValue: function (value) {
var owner = this;

value = value.toString();

owner.element.value = value;
owner.onInput(value);
},
Expand Down
7 changes: 6 additions & 1 deletion src/Cleave.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ var Cleave = React.createClass({
newValue = nextProps.value;

if (newValue) {
owner.onInput(newValue);
newValue = newValue.toString();

if (newValue !== owner.properties.initValue) {
owner.properties.initValue = newValue;
owner.onInput(newValue);
}
}

// update phone region code
Expand Down

0 comments on commit 7c8873d

Please sign in to comment.