Skip to content

Commit 9a30efb

Browse files
Fix issue #10 When using an object to modify both the :value and :options props, the options is not always modified before the value
Fix the issue where updating the `options` to new ones with a higher `decimalPlacesRawValue` loses the additional decimal places Now allows to update the `options` by passing an array of options (with objects and predefined option names) When the `options` and `value` are both set at the same time, `vue-autonumeric` now always update the `options` first, before setting the `value`. - This allows to use objects with the value and a predefined option name to modify the vue-autonumeric component. - Note: There is a know bug yet; if you use multiple `vue-autonumeric` component sharing the same `v-model` but *different* options, changing the value/option *may* not work correctly. - This is due to the fact that when vue-autonumeric detects a value change, it `set()` it since it does not come from a user interaction. - However if one of the `vue-autonumeric` component has a `decimalPlaces` option set to `2`, and another set to `5`, then the first component will drop the additional decimal places when using `set()`...which in turn will make the other component aware of that new value change, and the second component will then use that new cropped value as well. Signed-off-by: Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
1 parent a471910 commit 9a30efb

File tree

6 files changed

+173
-49
lines changed

6 files changed

+173
-49
lines changed

CHANGELOG.md

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

3+
### 1.1.0
4+
+ Fix issue #10 When using an object to modify both the `:value` and `:options` props, the options is not always modified before the value
5+
+ Fix the issue where updating the `options` to new ones with a higher `decimalPlacesRawValue` loses the additional decimal places
6+
+ Now allows to update the `options` by passing an array of options (with objects and predefined option names)
7+
+ When the `options` and `value` are both set at the same time, `vue-autonumeric` now always update the `options` first, before setting the `value`.
8+
+ This allows to use objects with the value and a predefined option name to modify the vue-autonumeric component.
9+
+ Note: There is a know bug yet; if you use multiple `vue-autonumeric` component sharing the same `v-model` but *different* options, changing the value/option *may* not work correctly.
10+
+ This is due to the fact that when vue-autonumeric detects a value change, it `set()` it since it does not come from a user interaction.
11+
+ However if one of the `vue-autonumeric` component has a `decimalPlaces` option set to `2`, and another set to `5`, then the first component will drop the additional decimal places when using `set()`...which in turn will make the other component aware of that new value change, and the second component will then use that new cropped value as well.
12+
313
### 1.0.7
414
+ Fix issue #9 Modifying the `options` will always lose the decimal places precision after `2` places
515
+ This happens since `resetOnOptions` temporarily resets the configuration to the default one, which set the `decimalPlaces` option to `2`.

dist/vue-autonumeric.js

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* vue-autonumeric v1.0.7 (https://github.com/autoNumeric/vue-autoNumeric)
2+
* vue-autonumeric v1.1.0 (https://github.com/autoNumeric/vue-autoNumeric)
33
* © 2018 Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
44
* Released under the MIT License.
55
*/
@@ -393,6 +393,15 @@ exports.default = {
393393
},
394394

395395

396+
computed: {
397+
anInfo: function anInfo() {
398+
return {
399+
value: this.value,
400+
options: this.options
401+
};
402+
}
403+
},
404+
396405
methods: {
397406
updateVModel: function updateVModel(event) {
398407
if (this.anElement !== null) {
@@ -422,29 +431,40 @@ exports.default = {
422431
},
423432

424433
watch: {
425-
value: function value(newValue, oldValue) {
426-
try {
427-
if (!this.userInteraction) {
428-
if (newValue !== oldValue) {
429-
this.anElement.set(newValue);
434+
anInfo: function anInfo(newValue, oldValue) {
435+
if (oldValue.options && (0, _stringify2.default)(newValue.options) !== (0, _stringify2.default)(oldValue.options)) {
436+
var optionsToUse = void 0;
437+
if (this.resetOnOptions) {
438+
if (Array.isArray(newValue.options)) {
439+
newValue.options = _AutoNumeric2.default.mergeOptions(newValue.options);
430440
}
431-
}
432-
} catch (error) {
433-
console.error(error);
434-
}
435441

436-
this.resetUserInteraction();
437-
},
438-
options: function options(newValue, oldValue) {
439-
if ((0, _stringify2.default)(newValue) !== (0, _stringify2.default)(oldValue)) {
440-
if (this.resetOnOptions) {
441442
var decimalPlacesRawValue = this.anElement.getSettings().decimalPlacesRawValue;
442-
var optionsToReset = (0, _assign2.default)({}, _AutoNumeric2.default.getDefaultConfig(), { decimalPlacesRawValue: decimalPlacesRawValue });
443+
var newOptions = _AutoNumeric2.default._getOptionObject(newValue.options);
444+
if (newOptions.decimalPlaces && newOptions.decimalPlaces > decimalPlacesRawValue) {
445+
optionsToUse = (0, _assign2.default)({}, _AutoNumeric2.default.getDefaultConfig(), newOptions);
446+
} else {
447+
optionsToUse = (0, _assign2.default)({}, _AutoNumeric2.default.getDefaultConfig(), { decimalPlacesRawValue: decimalPlacesRawValue }, newOptions);
448+
}
449+
} else {
450+
optionsToUse = newValue.options;
451+
}
443452

444-
this.anElement.update(optionsToReset);
453+
this.anElement.update(optionsToUse);
454+
}
455+
456+
if (newValue.value !== void 0) {
457+
try {
458+
if (!this.userInteraction) {
459+
if (newValue.value !== oldValue.value) {
460+
this.anElement.set(newValue.value);
461+
}
462+
}
463+
} catch (error) {
464+
console.error(error);
445465
}
446466

447-
this.anElement.update(newValue);
467+
this.resetUserInteraction();
448468
}
449469
}
450470
}

0 commit comments

Comments
 (0)