Fixed: Error when editing torrent indexer

This commit is contained in:
Mark McDowall 2019-02-14 09:14:16 -08:00
parent 223209e1eb
commit 9b212d11f0
1 changed files with 12 additions and 7 deletions

View File

@ -9,7 +9,7 @@ function parseValue(props, value) {
max max
} = props; } = props;
if (value == null) { if (value == null || value === '') {
return min; return min;
} }
@ -33,14 +33,18 @@ class NumberInput extends Component {
super(props, context); super(props, context);
this.state = { this.state = {
value: props.value.toString(), value: props.value == null ? '' : props.value.toString(),
isFocused: false isFocused: false
}; };
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (this.props.value !== prevProps.value && !this.state.isFocused) { const { value } = this.props;
this.setState({ value: this.props.value.toString() });
if (value !== prevProps.value && !this.state.isFocused) {
this.setState({
value: value == null ? '' : value.toString()
});
} }
} }
@ -69,19 +73,20 @@ class NumberInput extends Component {
const { value } = this.state; const { value } = this.state;
const parsedValue = parseValue(this.props, value); const parsedValue = parseValue(this.props, value);
const stringValue = parsedValue == null ? '' : parsedValue.toString();
if (parsedValue.toString() === value) { if (stringValue === value) {
this.setState({ isFocused: false }); this.setState({ isFocused: false });
} else { } else {
this.setState({ this.setState({
value: parsedValue.toString(), value: stringValue,
isFocused: false isFocused: false
}); });
} }
onChange({ onChange({
name, name,
value: parseValue(this.props, this.state.value) value: parsedValue
}); });
} }