Giter VIP home page Giter VIP logo

x-slayer / ezvalidator Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 4.0 393 KB

Dead simple field/object schema validation for flutter inspired by Yup

Home Page: https://pub.dev/packages/ez_validator

License: MIT License

Kotlin 0.09% Swift 0.76% Objective-C 0.02% Dart 72.90% HTML 2.54% CMake 11.85% C++ 10.90% C 0.93%
dart flutter form-validation form-validator object-validator validation yup yup-validation

ezvalidator's Introduction

๐Ÿ‘‹ Hello! I'm Iheb Briki known as X-SLAYER

I'm a full-stack developer and mainly use Flutter,React & nextJs

Remember, open source is not commercial software development. The projects I share here are just tools I've built for myself to make my life better. Be mindful and respect the time that I (and every other contributor) provide to the community free of charge. ๐Ÿ’œ

X-SLAYER

ezvalidator's People

Contributors

x-slayer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ezvalidator's Issues

instagram update

this is no issue but i wad wondering if you was gonna upload a updated verison for instaslayer desktop app

Desktop Support?

EzValidator is fantastic! I was wondering if there are plans to expand support to desktop platforms and what such an endeavor might entail?

Validators should work with empty values by default

When I pass a validator to a TextField and the validator is not required, it still returns an error when the value is null or empty.

I had to wrap the validators using this function

String? Function(String?) ifNotEmptyValidator(Function validator){
  return (String? value){
    if(value?.isEmpty ?? true){
      return null;
    }else{
      return validator(value);
    }
  };
}

...

ifNotEmptyValidator(EzValidator().phone("Incorrect Format").build())
ifNotEmptyValidator(EzValidator().url("Incorrect Format").build())

Then I checked Your Implementation and I found that Optional defaults to false, this is the main issue. Since you only have required function in the builder and not notRequired, then the default value for optional should be true, and should be changed to false when required is called, or you don't even need optional, if you always assume it's true unless required validation is added and call it first before all other validations.

class EzValidator {

  EzValidator();
  bool optional = true;
...
...

EzValidator required([String? message]) {
    optional = false;
    return _add((v) => v == null || v.trim().isEmpty
          ? message ?? globalLocale.required()
          : null);
  };
...
}

Or

without optional, the existence of requiredValidation is an indicator of whether it's optional or not.

class EzValidator {

  final List<StringValidationCallback> validations = [];
  StringValidationCallback? requiredValidation;

...
...
...

  String? _test(String? value) {
    
     if ( (requiredValidation ==null) && (value == null || value.isEmpty)) {
        return null;
      }
    for (var validate in [requiredValidation, ...validations]) {
 
      final result = validate(value);
      if (result != null) {
        return result;
      }
    }
    return null;
  }

...
...

EzValidator required([String? message]) {
    requiredValidation = ((v) => v == null || v.trim().isEmpty
          ? message ?? globalLocale.required()
          : null);
    return this;
  };
...
}

Or

Allow all validators to process nullable values and change _add to insert required validation at index 0, so the required validator will be called first.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.