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

Disable letters in Rate under Track Distance #7931

Merged
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ const CONST = {
KEYBOARD_TYPE: {
PHONE_PAD: 'phone-pad',
NUMBER_PAD: 'number-pad',
DECIMAL_PAD: 'decimal-pad',
},

ATTACHMENT_PICKER_TYPE: {
Expand Down
34 changes: 19 additions & 15 deletions src/pages/workspace/reimburse/WorkspaceReimburseNoVBAView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import compose from '../../../libs/compose';
import ONYXKEYS from '../../../ONYXKEYS';
import * as Policy from '../../../libs/actions/Policy';
import withFullPolicy from '../withFullPolicy';
import CONST from '../../../CONST';

const propTypes = {
/** The policy ID currently being configured */
Expand Down Expand Up @@ -56,17 +57,23 @@ class WorkspaceReimburseNoVBAView extends React.Component {
},
];

/**
* Set the rate throttled by 3 seconds so the user does not have to type over the corrected value
*/
updateRateValueThrottled = _.throttle((value) => {
this.setState({rateValue: this.getRateDisplayValue(value)});
updateRateValueDebounced = _.debounce((value) => {
kakajann marked this conversation as resolved.
Show resolved Hide resolved
const numValue = parseFloat(value).toFixed(2);
kakajann marked this conversation as resolved.
Show resolved Hide resolved

if (numValue === 'NaN') {
return;
}
kakajann marked this conversation as resolved.
Show resolved Hide resolved

this.setState({
rateValue: numValue.toString(),
kakajann marked this conversation as resolved.
Show resolved Hide resolved
});

Policy.setCustomUnitRate(this.props.policyID, this.state.unitID, {
customUnitRateID: this.state.rateID,
name: this.state.rateName,
rate: value * 100,
rate: numValue * 100,
kakajann marked this conversation as resolved.
Show resolved Hide resolved
}, null);
}, 3000, {leading: false, trailing: true});
}, 1000);

constructor(props) {
super(props);
Expand All @@ -93,17 +100,13 @@ class WorkspaceReimburseNoVBAView extends React.Component {
}
kakajann marked this conversation as resolved.
Show resolved Hide resolved

setRate(value) {
const numValue = parseFloat(value);
if (Number.isNaN(numValue)) {
this.setState({rateValue: ''});
return;
}
// allow only numbers and dot
kakajann marked this conversation as resolved.
Show resolved Hide resolved
const rateValue = value.replace(/[^0-9/.]/g, '');

// Set the immediate value so the user does not lose the input
this.setState({rateValue: numValue.toString()});
this.setState({rateValue});

// Set the corrected value with a delay and sync to the server
this.updateRateValueThrottled(numValue);
this.updateRateValueDebounced(rateValue);
}

setUnit(value) {
Expand Down Expand Up @@ -160,6 +163,7 @@ class WorkspaceReimburseNoVBAView extends React.Component {
value={this.state.rateValue}
autoCompleteType="off"
autoCorrect={false}
keyboardType={CONST.KEYBOARD_TYPE.DECIMAL_PAD}
/>
</View>
<View style={[styles.unitCol]}>
Expand Down