Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2024.02.xx] Fix #10663: adding decimals in the aeronautical form in searcg by coordinates (#10668) #10678

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading