vanshg395 / intl_phone_field

A customised Flutter TextFormField to input international phone number along with country code.
https://pub.dev/packages/intl_phone_field
MIT License
177 stars 505 forks source link

Field Validation #374

Open rawatpb65 opened 8 months ago

rawatpb65 commented 8 months ago

i have issue in validation. Suppose if user doesn't fill the phone field then form validation is not working until we interact with the field

          IntlPhoneField(
            initialCountryCode: 'IN',
            decoration: const InputDecoration(
              border: UnderlineInputBorder(),
              labelText: 'Mobile Number',
              labelStyle: TextStyle(color: Colors.black),
            ),
            validator: (value){print("sss${value}");
              if(value == null || value.number== "" ||value.number.toString().isEmpty){
                return "Please Enter Mobile Number";
              }
              return null;
            },
            onChanged: (phone) {
              setState(() {
                fullPhone = phone.completeNumber;
              });
            },
          ),

if i do this : autovalidateMode: AutovalidateMode.always, it shows validation before trigger on button so it's not accurate for me

can you gave me solution of this may be i missed something but i want validation on empty filed not on intreraction.

hani-hj1908619 commented 8 months ago

I was facing the same and I figured its an issue with the code. But since the repo is no longer maintained, we have to make our own fork and fix it there.

You can take a look at how I fixed it here

However, I'm pretty sure this would stop your custom validator from working if you're using one. I wasn't and I couldn't be bothered about it so I did this as a quick fix.

devsideal commented 6 months ago

Thanks @hani-hj1908619 Your solution worked for me, I just copy this file intl_phone_field.dart >> Renamed It >> Then Use It

dali010 commented 5 months ago

all these participants save my day thank you @hani-hj1908619 @devsideal @rawatpb65