icemanbsi / searchable_dropdown

MIT License
107 stars 162 forks source link

Validator Not Working Properly #106

Open Zujaj opened 3 years ago

Zujaj commented 3 years ago

I wrapped the SearchableDropdown.single inside a Form Widget which has a global key. I defined the SearchableDropdown's validator as (value)=> value == null ? 'field required' : null . On button pressed

onPressed: () {
               if (_myFormKey.currentState.validate()) {
                   // Show success message
                 }
               else {
                    // Show error                   
                }

The validator does not respond correctly and allows me to show success message on null values. Please look into this matter asap!

ariefyudia commented 3 years ago

I wrapped the SearchableDropdown.single inside a Form Widget which has a global key. I defined the SearchableDropdown's validator as (value)=> value == null ? 'field required' : null . On button pressed

onPressed: () {
               if (_myFormKey.currentState.validate()) {
                   // Show success message
                 }
               else {
                    // Show error                   
                }

The validator does not respond correctly and allows me to show success message on null values. Please look into this matter asap!

hi, i'm try to this, maybe can be solved your problem `String selectValidation;

validator: (value) => this.selectValidation,

validation: () { if (selectValidation== null) { setState(() { this.selectValidation= 'Skema is required'; }); } else { setState(() { this.skemaValidation = null; }); }

      if (!_formKey.currentState.validate()) {
        return "Fill form correctly";
      }
      return null;
    },`