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

View file

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