Skip to content

Commit

Permalink
Fix issue #432 The decimalCharacterAlternative option does not igno…
Browse files Browse the repository at this point in the history
…re the comma when it's set to `none`

Signed-off-by: Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
  • Loading branch information
AlexandreBonneau committed Feb 10, 2018
1 parent 2c482e3 commit df7d355
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
## Changelog for autoNumeric

### 4.1.0-beta.27
+ Fix issue #432 The `decimalCharacterAlternative` option does not ignore the comma when it's set to `none`

### 4.1.0-beta.26
+ Fix issue #522 Input is duplicated and reversed on devices with Android < 7.0
+ Remove the `input` event listener
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "autonumeric",
"version": "4.1.0-beta.26",
"version": "4.1.0-beta.27",
"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",
"readmeFilename": "README.md",
Expand Down
24 changes: 4 additions & 20 deletions src/AutoNumeric.js
@@ -1,8 +1,8 @@
/**
* AutoNumeric.js
*
* @version 4.1.0-beta.26
* @date 2018-02-10 UTC 09:10
* @version 4.1.0-beta.27
* @date 2018-02-10 UTC 23:59
*
* @authors Bob Knothe, Alexandre Bonneau
* @contributors Sokolov Yura and others, cf. AUTHORS
Expand Down Expand Up @@ -881,7 +881,7 @@ export default class AutoNumeric {
* @returns {string}
*/
static version() {
return '4.1.0-beta.26';
return '4.1.0-beta.27';
}

/**
Expand Down Expand Up @@ -7567,20 +7567,6 @@ To solve that, you'd need to either set \`decimalPlacesRawValue\` to \`null\`, o
}
}

/**
* Sets the alternative decimal separator key.
* @private
*/
_setAlternativeDecimalSeparatorCharacter() { //FIXME Delete this in order to fix issue #432
if (AutoNumericHelper.isNull(this.settings.decimalCharacterAlternative) && Number(this.settings.decimalPlaces) > 0) {
if (this.settings.decimalCharacter === '.' && this.settings.digitGroupSeparator !== ',') {
this.settings.decimalCharacterAlternative = ',';
} else if (this.settings.decimalCharacter === ',' && this.settings.digitGroupSeparator !== '.') {
this.settings.decimalCharacterAlternative = '.';
}
}
}

/**
* Caches regular expressions for _stripAllNonNumberCharactersExceptCustomDecimalChar
*
Expand Down Expand Up @@ -7836,7 +7822,6 @@ To solve that, you'd need to either set \`decimalPlacesRawValue\` to \`null\`, o

// Additional changes to the settings object
this._calculateVMinAndVMaxIntegerSizes();
this._setAlternativeDecimalSeparatorCharacter();
this._setTrailingNegativeSignInfo();
this.regex = {}; // Create the object that will store the regular expressions
this.constructor._cachesUsualRegularExpressions(this.settings, this.regex);
Expand Down Expand Up @@ -8491,8 +8476,7 @@ To solve that, you'd need to either set \`decimalPlacesRawValue\` to \`null\`, o
// Start rules when the decimal character key is pressed always use numeric pad dot to insert decimal separator
// Do not allow decimal character if no decimal part allowed
if (this.eventKey === this.settings.decimalCharacter ||
(this.settings.decimalCharacterAlternative && this.eventKey === this.settings.decimalCharacterAlternative) ||
(this.eventKey === '.' || this.eventKey === ',' || this.eventKey === AutoNumericEnum.keyName.NumpadDot)) { //FIXME Remove the hardcoded '.' and ',' for fixing issue #432?
(this.settings.decimalCharacterAlternative && this.eventKey === this.settings.decimalCharacterAlternative)) {
if (!this._isDecimalCharacterInsertionAllowed() || !this.settings.decimalCharacter) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AutoNumericHelper.js
Expand Up @@ -1098,7 +1098,7 @@ export default class AutoNumericHelper {
n = n.replace('.', '');
}

// length of string if no decimal character
// Length of string if no decimal character
if (e < 0) {
// Integer
e = n.length;
Expand Down
26 changes: 26 additions & 0 deletions test/e2e/index.html
Expand Up @@ -891,6 +891,16 @@ <h5 id="tag_h5">12345.67</h5>
</div>
</div>
</div>

<div class="testSuite">
<div class="test">
<p class="description">Issue #432</p>
<div>
<input id="issue_432_dot" type="text" placeholder="with dot as alternative">
<input id="issue_432_none" type="text" placeholder="without alternative">
</div>
</div>
</div>
</div>
<script>
//-------------- Classic input
Expand Down Expand Up @@ -1908,6 +1918,22 @@ <h5 id="tag_h5">12345.67</h5>

// Create all the element once
AutoNumeric.multiple('.multipleInitialization');

//-------------- Issue #432
new AutoNumeric('#issue_432_dot', [
'euro',
{
decimalCharacter : AutoNumeric.options.decimalCharacter.comma,
decimalCharacterAlternative: AutoNumeric.options.decimalCharacterAlternative.dot,
},
]);
new AutoNumeric('#issue_432_none', [
'euro',
{
decimalCharacter : AutoNumeric.options.decimalCharacter.comma,
decimalCharacterAlternative: AutoNumeric.options.decimalCharacterAlternative.none,
},
]);
</script>
</body>
</html>
39 changes: 39 additions & 0 deletions test/e2e/specs/autoNumeric.e2e.spec.js
Expand Up @@ -202,6 +202,8 @@ const selectors = {
issue478Neg4 : '#issue_478_neg4',
issue527input : '#issue_527',
issue527Blur : '#issue_527_blur',
issue432dot : '#issue_432_dot',
issue432none : '#issue_432_none',
};

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -3773,4 +3775,41 @@ describe('Pasting', () => {
});
});

describe('Issue #432', () => {
it('should test for default values, and focus on it', () => {
browser.url(testUrl);

expect(browser.getValue(selectors.issue432dot)).toEqual('');
expect(browser.getValue(selectors.issue432none)).toEqual('');
});

it('should accept the alternative decimal character', () => {
const inputWithDecimalCharAlternative = $(selectors.issue432dot);

inputWithDecimalCharAlternative.click();
// With the comma: ok
browser.keys('123,45');
expect(browser.getValue(selectors.issue432dot)).toEqual('123,45 €');

// With the dot: ok
browser.keys(['Home', 'Control', 'a', 'Control', 'Delete']);
browser.keys('123.45');
expect(browser.getValue(selectors.issue432dot)).toEqual('123,45 €');
});

it('should not accept any alternative decimal character', () => {
const inputWithoutDecimalCharAlternative = $(selectors.issue432none);

inputWithoutDecimalCharAlternative.click();
// With the comma: ok
browser.keys('123,45');
expect(browser.getValue(selectors.issue432none)).toEqual('123,45 €');

// With the dot: ko
browser.keys(['Home', 'Control', 'a', 'Control', 'Delete']);
browser.keys('123.45');
expect(browser.getValue(selectors.issue432none)).toEqual('12.345 €');
});
});

//TODO Add some tests to make sure the correct number of `AutoNumeric.events.formatted` is sent during each keypress

0 comments on commit df7d355

Please sign in to comment.