Skip to content

Commit

Permalink
Fix primefaces#2465: InputNumber default to min on allowEmpty=false
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Nov 25, 2021
1 parent 8461882 commit 4f24303
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/inputnumber/InputNumber.js
Expand Up @@ -783,13 +783,18 @@ export class InputNumber extends Component {

if (valueStr != null) {
newValue = this.parseValue(valueStr);
newValue = !newValue && !this.props.allowEmpty ? 0 : newValue;
newValue = this.evaluateEmpty(newValue);
this.updateInput(newValue, insertedValueStr, operation, valueStr);

this.handleOnChange(event, currentValue, newValue);
}
}

evaluateEmpty(newValue) {
const minimum = this.props.min || 0;
return !newValue && !this.props.allowEmpty ? minimum : newValue;
}

handleOnChange(event, currentValue, newValue) {
if (this.props.onChange && this.isValueChanged(currentValue, newValue)) {
this.props.onChange({
Expand Down Expand Up @@ -907,7 +912,7 @@ export class InputNumber extends Component {
}

updateInputValue(newValue) {
newValue = !newValue && !this.props.allowEmpty ? 0 : newValue;
newValue = this.evaluateEmpty(newValue);

const inputEl = this.inputRef.current;
const value = inputEl.value;
Expand All @@ -920,8 +925,8 @@ export class InputNumber extends Component {
}

formattedValue(val) {
const newVal = !val && !this.props.allowEmpty ? 0 : val;
return this.formatValue(newVal);
const newValue = this.evaluateEmpty(val);
return this.formatValue(newValue);
}

concatValues(val1, val2) {
Expand Down

0 comments on commit 4f24303

Please sign in to comment.