Skip to content

Commit

Permalink
Fix geosolutions-it#10663: adding decimals in the aeronautical form i…
Browse files Browse the repository at this point in the history
…n searcg by coordinates (geosolutions-it#10668)

* geosolutions-it#10663: fix adding decimals in the aeronautical form
Description:
- handle fixing the issue of prevent enters centesimal number after the comma/dot in aeronautical form and decimal form as well

* geosolutions-it#10663: fix adding decimals in the aeronautical form
Description:
- add helpful comment

* geosolutions-it#10663: edit unit test in IntlNumberFormatControl-test.jsx to fix FE failure

* geosolutions-it#10663: revert unnecessary change
  • Loading branch information
mahmoudadel54 committed Nov 14, 2024
1 parent 61cdc4e commit 6b33eda
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions web/client/components/I18N/IntlNumberFormControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class IntlNumberFormControl extends React.Component {
}}
componentClass={"input"}
className="form-control intl-numeric"
locale={this.context && this.context.intl && this.context.intl.locale || "en-US"}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ describe('IntlNumberFormControl', () => {
TestUtils.Simulate.change(element, {target: {value: '12.'}});
expect(element.value).toBe("12");
TestUtils.Simulate.change(element, {target: {value: '12.0'}});
expect(element.value).toBe("12");
expect(element.value).toBe("12.0");
TestUtils.Simulate.change(element, {target: {value: '12.04'}});
expect(element.value).toBe("12.04");
TestUtils.Simulate.change(element, {target: {value: '12.402'}});
expect(element.value).toBe("12.402");
TestUtils.Simulate.change(element, {target: {value: '-12.04'}});
expect(element.value).toBe("-12.04");
TestUtils.Simulate.change(element, {target: {value: '-12.40'}});
expect(element.value).toBe("-12.4");
expect(element.value).toBe("-12.40");
TestUtils.Simulate.change(element, {target: {value: '-12.0'}});
expect(element.value).toBe("-12");
expect(element.value).toBe("-12.0");
});
it('check calling passed onkeydown, onkeyup events', () => {
const intl = {locale: "en-US"};
Expand Down
13 changes: 10 additions & 3 deletions web/client/libs/numeric-input/NumericInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class NumericInput extends Component {
defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
strict: PropTypes.bool,
componentClass: PropTypes.string,
locale: PropTypes.string,
// eslint-disable-next-line consistent-return
mobile(props, propName) {
let prop = props[propName];
Expand Down Expand Up @@ -406,9 +407,15 @@ class NumericInput extends Component {
);

let loose = !this._isStrict && (this._inputFocus || !this._isMounted);

// incomplete number
if (loose && RE_INCOMPLETE_NUMBER.test(stringValue)) {
// create regex for numbers that contains centesimal decimal numbers
const numFormat = new Intl.NumberFormat(this.props.locale || "en-US");
const parts = numFormat.formatToParts(12345.6);
const decimalSymbol = parts.find(d => d.type === "decimal").value;
const escapedDecimalSymbol = decimalSymbol.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const RE_TRAILING_DECIMAL_ZEROS = new RegExp(`\\d+${escapedDecimalSymbol}\\d*0+`);

// incomplete number or number contains decimal symbol [centesimal decimal numbers]
if ((loose && RE_INCOMPLETE_NUMBER.test(stringValue)) || RE_TRAILING_DECIMAL_ZEROS.test(stringValue)) {
attrs.input.value = stringValue;
} else if (loose && stringValue && !RE_NUMBER.test(stringValue)) {// Not a number and not empty (loose mode only)
attrs.input.value = stringValue;
Expand Down

0 comments on commit 6b33eda

Please sign in to comment.