fix: Enhance contact number validation in organization form #43
@ -272,25 +272,40 @@ class _OrganizationFormState extends State<_OrganizationForm> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField(String fieldName, String label,
|
||||
{TextInputType keyboardType = TextInputType.text}) {
|
||||
final controller = validator.getController(fieldName);
|
||||
final validatorFunc = validator.getValidation<String>(fieldName);
|
||||
Widget _buildTextField(String fieldName, String label,
|
||||
{TextInputType keyboardType = TextInputType.text}) {
|
||||
final controller = validator.getController(fieldName);
|
||||
final defaultValidator = validator.getValidation<String>(fieldName);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
keyboardType: keyboardType,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
validator: validatorFunc,
|
||||
),
|
||||
);
|
||||
// Custom logic for contact number
|
||||
String? Function(String?)? validatorFunc = defaultValidator;
|
||||
if (fieldName == 'contactNumber') {
|
||||
validatorFunc = (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Contact number is required';
|
||||
}
|
||||
if (!RegExp(r'^\d{10}$').hasMatch(value)) {
|
||||
return 'Enter a valid 10-digit contact number';
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
keyboardType: keyboardType,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
validator: validatorFunc,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void _submitForm() async {
|
||||
bool isValid = validator.validateForm();
|
||||
|
||||
@ -308,7 +323,7 @@ class _OrganizationFormState extends State<_OrganizationForm> {
|
||||
}
|
||||
|
||||
if (isValid) {
|
||||
setState(() => _loading = true);
|
||||
setState(() => _loading = true);
|
||||
|
||||
final formData = validator.getData();
|
||||
|
||||
@ -326,7 +341,7 @@ class _OrganizationFormState extends State<_OrganizationForm> {
|
||||
|
||||
final error = await AuthService.requestDemo(requestBody);
|
||||
|
||||
setState(() => _loading = false);
|
||||
setState(() => _loading = false);
|
||||
|
||||
if (error == null) {
|
||||
showAppSnackbar(
|
||||
|
Loading…
x
Reference in New Issue
Block a user