Prevent negative price setting in input

This commit is contained in:
Dawid Tarasiuk 2020-10-05 18:19:07 +02:00
parent bf295e4dce
commit 5d1361f352
2 changed files with 25 additions and 3 deletions

View file

@ -37,6 +37,12 @@ const ProductPricing: React.FC<ProductPricingProps> = props => {
const formErrors = getFormErrors(["basePrice"], errors); const formErrors = getFormErrors(["basePrice"], errors);
const handlePriceChange = event => {
if (/^\d*(\.\d+)?$/.test(event.target.value)) {
onChange(event);
}
};
return ( return (
<Card> <Card>
<CardTitle <CardTitle
@ -58,7 +64,7 @@ const ProductPricing: React.FC<ProductPricingProps> = props => {
name="basePrice" name="basePrice"
value={data.basePrice} value={data.basePrice}
currencySymbol={currency} currencySymbol={currency}
onChange={onChange} onChange={handlePriceChange}
InputProps={{ InputProps={{
inputProps: { inputProps: {
min: 0 min: 0

View file

@ -36,6 +36,12 @@ const ProductVariantPrice: React.FC<ProductVariantPriceProps> = props => {
const formErrors = getFormErrors(["price", "cost_price"], errors); const formErrors = getFormErrors(["price", "cost_price"], errors);
const handlePriceChange = event => {
if (/^\d*(\.\d+)?$/.test(event.target.value)) {
onChange(event);
}
};
return ( return (
<Card> <Card>
<CardTitle <CardTitle
@ -55,8 +61,13 @@ const ProductVariantPrice: React.FC<ProductVariantPriceProps> = props => {
})} })}
value={price} value={price}
currencySymbol={currencySymbol} currencySymbol={currencySymbol}
onChange={onChange} onChange={handlePriceChange}
disabled={loading} disabled={loading}
InputProps={{
inputProps: {
min: "0"
}
}}
/> />
</div> </div>
<div> <div>
@ -76,8 +87,13 @@ const ProductVariantPrice: React.FC<ProductVariantPriceProps> = props => {
} }
value={costPrice} value={costPrice}
currencySymbol={currencySymbol} currencySymbol={currencySymbol}
onChange={onChange} onChange={handlePriceChange}
disabled={loading} disabled={loading}
InputProps={{
inputProps: {
min: "0"
}
}}
/> />
</div> </div>
</div> </div>