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