Code Monkey home page Code Monkey logo

formdator's Introduction

formdator

EO-Color logo

EO principles respected here DevOps By Rultor.com

pub license PDD status

build codecov CodeFactor Grade style: lint Hits-of-Code

Contents

Overview

FormdatorFormidable Validator.

Formdator is a fully object-oriented package for validating Flutter form fields. Its main benefits, compared to all other similar packages, include:

  • Dependency-free: there is only pure Dart code.
  • Object-oriented mindset: the elements for validation are immutable objects that can be combined in various configurations.
  • Classes with short — yet meaningful — names like Req for required fields; ReqEmail for non-empty, well-formed emails; Len for length constraints; Int for integer-only values; and so on.
  • Easy-to-compose validators: e.g., the command Trim(Email()) produces a validator that trims an email value before validating it.
  • Multiple validation at once: you can apply multiple validation rules at once by using the Pair or Rules classes.
  • Built-in set of compound validators: e.g., to validate an email and limit its length to a maximum of 50 characters, simply use an instance of Email.len(50)write less; do more!

For easier integration with Flutter form fields, every validator implements the call() method. As a result, any validator object can be called as a function — Callable Classes.

Getting Started

The following code snippet demonstrates how you can easily group the Rules, Req, Len and Email classes together to create a kind of 'email-max-50-characters' constraint.

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      validator: Rules<String>([ // The "Rules" class performs multiple validations at once.
        Req(blank: 'Please enter the email'), // "blank" is the error message in case of field left blank.
        Len.max(50, long: 'Email length cannot exceed 50 characters'), // "long" is the error message if an input value is too long.
        Email(mal: 'Malformed email'), // "mal" is the error message in case of malformed email.
      ]),
    );
  }

Or — even better — use the compound validator ReqEmail to perform the same task.

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      validator: ReqEmail.len(
        50,
        blank: 'Please enter the email',
        mal: 'Malformed email',
        long: 'Email length cannot exceed 50 characters',
      ),
    );
  }

The shorter command ReqEmail.len(50) is equivalent to the much longer command Rules<String>([Req(), Len.max(50), Email()]) — write less; do more!

List of Validators

For a complete list of validators with detailed information about each one (constructors, parameters, etc.):

Grouped by Category

  • brazil — validators related to Brazil (BrMobile, BrPhone, Cep, Cnpj, Cpf, etc.).
  • core — core validators (Len, Match [text pattern], Pair, Req, Rules, Trim, etc.).
  • logic — validation logic and unit testing (Equal, Ok, Nok, ValueBack).
  • net — internet (Email, Ipv4, Ipv6, MacAddr, Url, etc.).
  • numeric — validators related to numbers or digits (Digit, Hex, Int, Num, etc.).

Demo application

The demo application provides a fully working example, focused on demonstrating exactly four validators in action — Pair, ReqLen, ReqEmail, and Equal. You can take the code in this demo and experiment with it.

To run the demo application:

  git clone https://github.com/dartoos-dev/formdator.git
  cd formdator/example/
  flutter run -d chrome

This should launch the demo application on Chrome in debug mode.

formdator-demo-app

Contribute

Contributors are welcome!

  1. Open an issue regarding an improvement, a bug you noticed, or ask to be assigned to an existing one.
  2. If the issue is confirmed, fork the repository, do the changes on a separate branch and make a Pull Request.
  3. After review and acceptance, the Pull Request is merged and closed.

Make sure the command below passes before making a Pull Request.

  dart analyze && sudo dart test

References

formdator's People

Contributors

rafamizes avatar rultor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

formdator's Issues

Multitype MaxLen and MinLen

In addition to the String type, the MaxLen and MinLen validators should also handle other types that contain the length property; for example, lists and maps.

Release 0.2.1

This release should fix the CHANGELOG's "unreleased" section.

Demo application

Develop a demo application as an example of how to use this package effectively.

Fix and improve README

Turn it more "elegant" by:

  • writing a better descripion of the package's purposes
  • placing the project logo as the top element
  • Initializing the Getting Started section
  • EO Principles badge
  • Rultor badge
  • pub badge
  • license badge
  • lint badge
  • PDD badge
  • CI status badge
  • codecov badge
  • Hits-of-Code badge

First things first

The 'callor' repo has just been transferred from @rafamizes to @dartoosdev's.

First things first:

  • MIT license
  • turn this repo public
  • create proper issue labels
  • label this issue with CI and build tags
  • add this issue to the "Resurrection" Milestone
  • grant Write permission access to rultor bot
  • grant Triage permission access to 0pdd bot
  • add 0ppd link as webhook
  • configure test coverage -- codecov
  • grant friendship to rafamizes/secret
  • fork this repo
  • from the root directory, run flutter format lib/ test/ example/ -- the CI format analyzes phase won't pass otherwise
  • add at least one test case -- the CI test phase won't pass otherwise
  • create the example directory and a main.dart file within it.
  • set up branch protection -- read-only master
  • set up CI pipeline -- github action and rultor

Migrating to null safety

Steps for migration:

  • check dependency status: dart pub outdated --mode=null-safety
  • update dependencies to null-safety releases, if they exist: dart pub upgrade --null-safety
  • run Dart's migration tool dart migrate and fix the reported issues

migration guide

Shorten the package description

Flutter package repo:

  • "keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters."

Num class refactoring

Keep the default constructor, but split its functionality into 3 new ctors:

  • Num.max to constrain the maximum value.
  • Num.min to constrain the minimum value.
  • Num.range to constrain a value within a range.

README improvements

Implement the following improvements:

  • reorder the badge section by creating three rows. Distribute the badges according to the most up-to-date Dartoos standard.
  • a table showing all implemented validators — their names and usage examples
  • fix some typos, e.g. replace ordinary dashes "-" with real M dashes "—" when appropriate
  • in the "Demo application" section, replace "four" with "three" as the example uses three and not four validators
  • add two additional badges to it: documentation link and code quality

Full implementation of the 'Digit' class

The following constructors are required for the 'Digit' validator:

  • 'Digit.fix' for fixed-length digits
  • 'Digit.min' to set a minimum length
  • 'Digit.max' to set a maximum length
  • 'Digit.range' to set a range of valid lengths

Rename the validator types aliases

Rename the typedefs that are used as type aliases so that each typedef begins with the prefix 'Val' -- short for 'validator' -- followed by an abbreviation for the type. For example, 'ObjVal' becomes 'ValObj'; 'StrVal', ValStr'; and so on.

Implement Cep and ReqCep validators along with the CepStrip utility class

Cep (Código de Endereçamento Postal) is the Brazilian equivalent of zip code or postal code. The standard format is "nnnnn-nnn" (the original five digits, a hyphen, and the new three digits).

The 'CepStrip' class transforms a well-formed 'CEP' value into a plain value, that is, it retrieves the 8 digits without the hyphen "-". In case of a malformed input 'CEP value, the class will return null.

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.