Skip to content

Commit

Permalink
Fixes #596 Change event not firing depending on cursor movement
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
  • Loading branch information
AlexandreBonneau committed Jul 25, 2018
1 parent 0440588 commit 81bf36c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
## Changelog for autoNumeric

### 4.3.4
+ Fixes #596 Change event not firing depending on cursor movement

### 4.3.3
+ Fixes #593 Pasting a negative value over a negative value that as a currency symbol and its numbers selected throws an error
+ Refactor the `_onPaste()` handler by removing duplicated parts
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "autonumeric",
"version": "4.3.3",
"version": "4.3.4",
"description": "autoNumeric is a standalone Javascript library that provides live *as-you-type* formatting for international numbers and currencies. It supports most international numeric formats and currencies including those used in Europe, Asia, and North and South America.",
"main": "dist/autoNumeric.js",
"module": "src/main.js",
Expand Down
8 changes: 4 additions & 4 deletions src/AutoNumeric.js
@@ -1,8 +1,8 @@
/**
* AutoNumeric.js
*
* @version 4.3.3
* @date 2018-07-25 UTC 20:35
* @version 4.3.4
* @date 2018-07-25 UTC 20:28
*
* @authors Bob Knothe, Alexandre Bonneau
* @contributors Sokolov Yura and others, cf. AUTHORS
Expand Down Expand Up @@ -890,7 +890,7 @@ export default class AutoNumeric {
* @returns {string}
*/
static version() {
return '4.3.3';
return '4.3.4';
}

/**
Expand Down Expand Up @@ -6073,7 +6073,6 @@ To solve that, you'd need to either set \`decimalPlacesRawValue\` to \`null\`, o
_onFocusInAndMouseEnter(e) {
//TODO Create separate handlers for the focus and mouseenter events
this.isEditing = false; // Just in case no `keyUp` event have been sent (ie. if the user lost the focus from the current window while typing)
this.rawValueOnFocus = this.rawValue; // Keep track of the initial rawValue. This is needed to define if a change event must be dispatched later

if (this.settings.unformatOnHover && e.type === 'mouseenter' && e.altKey) {
this.constructor._unformatAltHovered(this);
Expand All @@ -6084,6 +6083,7 @@ To solve that, you'd need to either set \`decimalPlacesRawValue\` to \`null\`, o
if (e.type === 'focus') { //TODO Move that back to the 'focus' event handler when the separation between the 'focus' and 'mouseenter' handler will be done
// Keep track if the element is currently focused
this.isFocused = true;
this.rawValueOnFocus = this.rawValue; // Keep track of the initial rawValue. This is needed to define if a change event must be dispatched later
}

if (e.type === 'focus' && this.settings.unformatOnHover && this.hoveredWithAlt) {
Expand Down
21 changes: 21 additions & 0 deletions test/e2e/index.html
Expand Up @@ -988,6 +988,16 @@ <h5 id="tag_h5">12345.67</h5>
</div>
</div>
</div>

<div class="testSuite">
<div class="test">
<p class="description">Issue #596</p>
<div>
<input id="issue_596" type="text" placeholder="" value="-1357246.81">
<input id="issue_596_change_detector" type="text">
</div>
</div>
</div>
</div>
<script>
//-------------- Classic input
Expand Down Expand Up @@ -2108,6 +2118,17 @@ <h5 id="tag_h5">12345.67</h5>
//-------------- Issue #593
new AutoNumeric('#issue_593_truncate', -1, ['French', { onInvalidPaste: AutoNumeric.options.onInvalidPaste.truncate }]);
new AutoNumeric('#issue_593', -1, 'French');

//-------------- Issue #596
const issue596 = new AutoNumeric('#issue_596');
const issue596ChangeDetector = document.querySelector('#issue_596_change_detector');

let issue596ChangeCount = 0;
issue596ChangeDetector.value = 0;

issue596.node().addEventListener('change', () => {
issue596ChangeDetector.value = ++issue596ChangeCount;
});
</script>
</body>
</html>

0 comments on commit 81bf36c

Please sign in to comment.