feat: Add comprehensive validation for expense submission fields in bottom sheet

This commit is contained in:
Vaibhav Surve 2025-09-11 17:32:13 +05:30
parent 20365697a7
commit 229531c5bf

View File

@ -118,7 +118,61 @@ class _AddExpenseBottomSheetState extends State<_AddExpenseBottomSheet> {
onCancel: Get.back, onCancel: Get.back,
onSubmit: () { onSubmit: () {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
// Additional dropdown validation
if (controller.selectedProject.value.isEmpty) {
showAppSnackbar(
title: "Error",
message: "Please select a project",
type: SnackbarType.error,
);
return;
}
if (controller.selectedExpenseType.value == null) {
showAppSnackbar(
title: "Error",
message: "Please select an expense type",
type: SnackbarType.error,
);
return;
}
if (controller.selectedPaymentMode.value == null) {
showAppSnackbar(
title: "Error",
message: "Please select a payment mode",
type: SnackbarType.error,
);
return;
}
if (controller.selectedPaidBy.value == null) {
showAppSnackbar(
title: "Error",
message: "Please select a person who paid",
type: SnackbarType.error,
);
return;
}
if (controller.attachments.isEmpty &&
controller.existingAttachments.isEmpty) {
showAppSnackbar(
title: "Error",
message: "Please attach at least one document",
type: SnackbarType.error,
);
return;
}
// Validation passed, submit
controller.submitOrUpdateExpense(); controller.submitOrUpdateExpense();
} else {
showAppSnackbar(
title: "Error",
message: "Please fill all required fields correctly",
type: SnackbarType.error,
);
} }
}, },
child: SingleChildScrollView( child: SingleChildScrollView(
@ -186,12 +240,6 @@ class _AddExpenseBottomSheetState extends State<_AddExpenseBottomSheet> {
_CustomTextField( _CustomTextField(
controller: controller.gstController, controller: controller.gstController,
hint: "Enter GST No.", hint: "Enter GST No.",
validator: (value) {
if (value != null && value.isNotEmpty) {
return Validators.gstValidator(value);
}
return null;
},
), ),
MySpacing.height(16), MySpacing.height(16),
@ -284,7 +332,7 @@ class _AddExpenseBottomSheetState extends State<_AddExpenseBottomSheet> {
if (value != null && value.isNotEmpty) { if (value != null && value.isNotEmpty) {
return Validators.transactionIdValidator(value); return Validators.transactionIdValidator(value);
} }
return null; return null;
}, },
), ),