Skip to content

Commit

Permalink
fixed decimal symbol property
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenMasterJacob20011 committed Jul 2, 2024
1 parent 12a035b commit e370c98
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/number/Number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 18 additions & 0 deletions src/components/number/Number.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
comp5,
comp6,
comp7,
comp8
} from './fixtures';

describe('Number Component', () => {
Expand Down Expand Up @@ -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);
//
Expand Down
26 changes: 26 additions & 0 deletions src/components/number/fixtures/comp8.js
Original file line number Diff line number Diff line change
@@ -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
}
]
}
3 changes: 2 additions & 1 deletion src/components/number/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

0 comments on commit e370c98

Please sign in to comment.