fix: correctly validate number inputs against null/NaN bypass in admin modals
This commit is contained in:
@@ -40,6 +40,9 @@
|
||||
let serviceErrors = $state<Record<string, string>>({});
|
||||
|
||||
function validatePrice(price: any): string {
|
||||
if (price === null || price === undefined || price === '') {
|
||||
return 'Price is required';
|
||||
}
|
||||
const numPrice = parseFloat(price);
|
||||
if (isNaN(numPrice)) {
|
||||
return 'Price must be a valid number';
|
||||
@@ -57,20 +60,24 @@
|
||||
return '';
|
||||
}
|
||||
|
||||
function validateDuration(value: number, field: string): string {
|
||||
if (isNaN(value)) {
|
||||
function validateDuration(value: any, field: string): string {
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return 'Field cannot be empty';
|
||||
}
|
||||
const num = Number(value);
|
||||
if (isNaN(num)) {
|
||||
return 'Must be a valid number';
|
||||
}
|
||||
|
||||
if (!Number.isInteger(value)) {
|
||||
if (!Number.isInteger(num)) {
|
||||
return 'Must be a whole number';
|
||||
}
|
||||
|
||||
if (field === 'duration_minutes' && value <= 0) {
|
||||
if (field === 'duration_minutes' && num <= 0) {
|
||||
return 'Duration must be greater than 0';
|
||||
}
|
||||
|
||||
if (field === 'minimum_age_required' && (value < 0 || value > 100)) {
|
||||
if (field === 'minimum_age_required' && (num < 0 || num > 100)) {
|
||||
return 'Must be between 0 and 100';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user