diff --git a/src/components/number/Number.js b/src/components/number/Number.js index 3d90c287fd..6678047b8e 100644 --- a/src/components/number/Number.js +++ b/src/components/number/Number.js @@ -54,7 +54,7 @@ export default class NumberComponent extends Input { const separators = getNumberSeparators(this.options.language || navigator.language); - this.decimalSeparator = this.options.decimalSeparator = this.options.decimalSeparator + this.decimalSeparator = this.options.decimalSeparator = this.component.decimalSymbol || this.options.decimalSeparator || this.options.properties?.decimalSeparator || separators.decimalSeparator; diff --git a/src/components/number/Number.unit.js b/src/components/number/Number.unit.js index 79aa6c1b24..e6a76c8c0a 100644 --- a/src/components/number/Number.unit.js +++ b/src/components/number/Number.unit.js @@ -13,6 +13,7 @@ import { comp5, comp6, comp7, + comp8 } from './fixtures'; describe('Number Component', () => { @@ -423,6 +424,23 @@ describe('Number Component', () => { }).catch(done); }); + it('Should not remove decimal symbol and numbers after decimal symbol when submit is pressed', (done) => { + Formio.createForm(document.createElement('div'), comp8, {}).then((form) => { + const inputEvent = new Event('input'); + const numberComponent = form.getComponent('number'); + const buttonComponent = form.getComponent('submit'); + numberComponent.refs.input[0].value = "123-456"; + numberComponent.refs.input[0].dispatchEvent(inputEvent); + setTimeout(()=>{ + buttonComponent.refs.button.click(); + setTimeout(()=>{ + assert.equal(numberComponent.refs.input[0].value, "123-456"); + done(); + },200); + },200); + }); + }); + // it('Should add trailing zeros on blur, if decimal required', (done) => { // const comp = _.cloneDeep(comp3); // diff --git a/src/components/number/fixtures/comp8.js b/src/components/number/fixtures/comp8.js new file mode 100644 index 0000000000..da06ccd63e --- /dev/null +++ b/src/components/number/fixtures/comp8.js @@ -0,0 +1,26 @@ +export default { + components: [ + { + "label": "Number", + "applyMaskOn": "change", + "mask": false, + "tableView": false, + "delimiter": false, + "requireDecimal": false, + "inputFormat": "plain", + "truncateMultipleSpaces": false, + "key": "number", + "type": "number", + "input": true, + "decimalSymbol": "-" + }, + { + "type": "button", + "label": "Submit", + "key": "submit", + "disableOnInvalid": true, + "input": true, + "tableView": false + } + ] +} diff --git a/src/components/number/fixtures/index.js b/src/components/number/fixtures/index.js index a94dca0b41..9b740a1c92 100644 --- a/src/components/number/fixtures/index.js +++ b/src/components/number/fixtures/index.js @@ -5,4 +5,5 @@ import comp4 from './comp4'; import comp5 from './comp5'; import comp6 from './comp6'; import comp7 from './comp7'; -export { comp1, comp2, comp3, comp4, comp5, comp6, comp7 }; +import comp8 from './comp8'; +export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8 };