Skip to content

Commit a60a48c

Browse files
Fix issue #8 Add a new resetOnOptions props so that updating the options one first reset to the default options
Signed-off-by: Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
1 parent 43ad9a1 commit a60a48c

File tree

7 files changed

+38
-11
lines changed

7 files changed

+38
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Changelog for vue-autoNumeric
22

3+
### 1.0.6
4+
+ Fix issue #8 Add a new `resetOnOptions` props so that updating the `options` one first reset to the default options
5+
+ Add a `resetOnOptions` props set the `true` by default so that updating the `options` prop first call `.options.reset()`
6+
+ This is useful when using predefined option names that do not declare all the options. For instance when switching from `'integer'` to `'euro'`, the `decimalPlaces` was not set from `0` to `2` and you had to first update to the default configuration.
7+
+ Now by default all options update will reset to the default options first. This can be avoided by setting `resetOnOptions` to false before changing the `options` value.
8+
39
### 1.0.5
410
+ Fix issue #2 Allow the component to generate any supported Html element instead of only `<input>`
511

dist/vue-autonumeric.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* vue-autonumeric v1.0.5 (https://github.com/autoNumeric/vue-autoNumeric)
2+
* vue-autonumeric v1.0.6 (https://github.com/autoNumeric/vue-autoNumeric)
33
* © 2018 Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
44
* Released under the MIT License.
55
*/
@@ -342,6 +342,12 @@ exports.default = {
342342
}
343343
},
344344

345+
resetOnOptions: {
346+
type: Boolean,
347+
required: false,
348+
default: true
349+
},
350+
345351
placeholder: {
346352
type: String,
347353
required: false
@@ -431,6 +437,10 @@ exports.default = {
431437
},
432438
options: function options(newValue, oldValue) {
433439
if ((0, _stringify2.default)(newValue) !== (0, _stringify2.default)(oldValue)) {
440+
if (this.resetOnOptions) {
441+
this.anElement.options.reset();
442+
}
443+
434444
this.anElement.update(newValue);
435445
}
436446
}

dist/vue-autonumeric.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples-src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
import VueAutonumeric from '../src/components/VueAutonumeric.vue';
134134
135135
export default {
136-
name : 'app',
136+
name: 'app',
137137
138138
components: {
139139
VueAutonumeric,
@@ -188,7 +188,7 @@
188188
return 'euro';
189189
}
190190
191-
return 'dollar';
191+
return ['dollar', { decimalPlaces: 0 }];
192192
},
193193
},
194194
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-autonumeric",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "An AutoNumeric wrapper for Vue.js",
55
"author": "Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>",
66
"license": "MIT",
@@ -39,7 +39,7 @@
3939
"components"
4040
],
4141
"dependencies": {
42-
"autonumeric": "^4.1.0-beta.24"
42+
"autonumeric": "^4.2.3"
4343
},
4444
"devDependencies": {
4545
"autoprefixer": "^6.7.7",

src/components/VueAutonumeric.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!--
22
vue-autonumeric
33
4-
@version 1.0.5
5-
@date 2018-02-01 UTC 22:00
4+
@version 1.0.6
5+
@date 2018-02-27 UTC 00:45
66
77
@author Alexandre Bonneau
88
@copyright 2018 © Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
@@ -120,6 +120,12 @@ OTHER DEALINGS IN THE SOFTWARE.
120120
},
121121
},
122122
123+
resetOnOptions: {
124+
type : Boolean,
125+
required: false,
126+
default : true,
127+
},
128+
123129
placeholder: { // The <input> placeholder text. This is only used if the generated element is an <input>.
124130
type : String,
125131
required: false,
@@ -263,6 +269,11 @@ OTHER DEALINGS IN THE SOFTWARE.
263269
264270
options(newValue, oldValue) {
265271
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) { //TODO Find a better way (without external libraries) to compare the two objects
272+
if (this.resetOnOptions) {
273+
// This is needed when using predefined options that do not override previously used options
274+
this.anElement.options.reset();
275+
}
276+
266277
// Compare the new and old option, and only update if they are different
267278
this.anElement.update(newValue);
268279
}

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ asynckit@^0.4.0:
228228
version "0.4.0"
229229
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
230230

231-
autonumeric@^4.1.0-beta.24:
232-
version "4.1.0-beta.24"
233-
resolved "https://registry.yarnpkg.com/autonumeric/-/autonumeric-4.1.0-beta.24.tgz#1ea2994663fb6339687265386c25d61e31b1997f"
231+
autonumeric@^4.2.3:
232+
version "4.2.3"
233+
resolved "https://registry.yarnpkg.com/autonumeric/-/autonumeric-4.2.3.tgz#451e9a3620b2bbb075b25b567a9f76c08521aee1"
234234

235235
autoprefixer@^6.3.1, autoprefixer@^6.7.7:
236236
version "6.7.7"

0 commit comments

Comments
 (0)