All Projects → tminglei → form-binder

tminglei / form-binder

Licence: BSD-2-Clause license
A micro data binding and validating framework, very easy to use and hack

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to form-binder

form-binder-java
Java port of form-binder, a micro data binding and validating framework
Stars: ✭ 29 (+61.11%)
Mutual labels:  data-validation, data-binding
Wires
Light binding library for Xamarin
Stars: ✭ 34 (+88.89%)
Mutual labels:  data-binding
Saul
Data validation and conformation library for Elixir.
Stars: ✭ 62 (+244.44%)
Mutual labels:  data-validation
minimallist
A minimalist data driven data model library, inspired by Clojure Spec and Malli.
Stars: ✭ 63 (+250%)
Mutual labels:  data-validation
React Jsonschema Form
A React component for building Web forms from JSON Schema.
Stars: ✭ 10,870 (+60288.89%)
Mutual labels:  data-validation
RxBinding
Simple data binding operators ~> and <~> for RxSwift.
Stars: ✭ 61 (+238.89%)
Mutual labels:  data-binding
Pywhip
💂‍♂️ Python package to validate data against whip specifications
Stars: ✭ 5 (-72.22%)
Mutual labels:  data-validation
data-mediator
a data mediator framework bind callbacks for any property
Stars: ✭ 66 (+266.67%)
Mutual labels:  data-binding
objectiv-analytics
Powerful product analytics for data teams, with full control over data & models.
Stars: ✭ 399 (+2116.67%)
Mutual labels:  data-validation
Dry Schema
Coercion and validation for data structures
Stars: ✭ 249 (+1283.33%)
Mutual labels:  data-validation
Data Cleaning 101
Data Cleaning Libraries with Python
Stars: ✭ 243 (+1250%)
Mutual labels:  data-validation
Typical
Typical: Fast, simple, & correct data-validation using Python 3 typing.
Stars: ✭ 111 (+516.67%)
Mutual labels:  data-validation
swipeablerecyclerview
SwipeableRecyclerView provides a wrapper class SwipeItemTouchHelperCallback which can be used to add Dragging capability to your RecyclerView items. You can make use of DataBinding to bind it via XML.
Stars: ✭ 16 (-11.11%)
Mutual labels:  data-binding
Passable
Declarative data validations.
Stars: ✭ 93 (+416.67%)
Mutual labels:  data-validation
aka-ios-beacon
The missing binding framework for iOS
Stars: ✭ 13 (-27.78%)
Mutual labels:  data-binding
Dry Validation
Validation library with type-safe schemas and rules
Stars: ✭ 1,087 (+5938.89%)
Mutual labels:  data-validation
Cerberus
Lightweight, extensible data validation library for Python
Stars: ✭ 2,640 (+14566.67%)
Mutual labels:  data-validation
nytclient-android
This sample app is created to demonstrate the usage of Android Architecture Components with MVVM architecture
Stars: ✭ 24 (+33.33%)
Mutual labels:  data-binding
NestedReact
BackboneJS compatibility layer for React-MVx MVVM framework.
Stars: ✭ 79 (+338.89%)
Mutual labels:  data-binding
Kriptofolio
Free open source minimalistic cryptocurrencies portfolio app for Android.
Stars: ✭ 79 (+338.89%)
Mutual labels:  data-binding

form-binder

Build Status

Form-binder is a micro data binding and validating framework, very easy to use and hack.

It was initially created for my Scalatra-based project, but you can easily integrate it with other frameworks.

Features

  • very lightweight, only ~900 lines codes (framework + built-in extensions)
  • easy use, no verbose codes, and what you see is what you get
  • high customizable, you can extend almost every executing point
  • easily extensible, every extension interface is an alias of FunctionN
  • immutable, you can share mapping definition object safely

Usage

form-binder description

Steps:

  1. define your binder
  2. define your mappings
  3. prepare your data
  4. bind and consume

p.s. every points above (1)/(2)/(3)/(4)/ are all extendable and you can easily customize it.

Install & Integrate

To use form-binder, pls add the dependency to your sbt project file:

libraryDependencies += "com.github.tminglei" %% "form-binder" % "0.12.2"

Then you can integrate it with your framework to simplify normal usage.

Here's the way in my Scalatra project:

First, I defined a FormBindSupport trait,

trait MyFormBindSupport extends I18nSupport { self: ScalatraBase =>
  import MyFormBindSupport._

  before() {
    request(BindMessagesKey) = Messages(locale, bundlePath = "bind-messages")
  }

  def binder(implicit request: HttpServletRequest) = FormBinder(bindMessages.get, errsTree())

  ///
  private def bindMessages(implicit request: HttpServletRequest): Messages = if (request == null) {
    throw new ScalatraException("There needs to be a request in scope to call bindMessages")
  } else {
    request.get(BindMessagesKey).map(_.asInstanceOf[Messages]).orNull
  }
}

Then mix it to my xxxServlet, and use it like this,

import com.github.tminglei.bind.simple._

class SampleServlet extends ScalatraServlet with MyFormBindSupport {

  get("/:id") {
    val mappings = tmapping(
      "id" -> long()
    )
    binder.bind(mappings, params).fold(
      errors => holt(400, errors),
      { case (id) =>
        Ok(toJson(repos.features.get(id)))
      }
    )
  }
}

p.s. you can check more integration sample codes under /integrations.

How it works

Principle

The core of form-binder is Mapping, tree structure mappings. With depth-first algorithm, it was used to validate data and construct the result value object.

Details

form-binder description

Major Components:

[1] binder: facade, used to bind and trigger processing, two major methods: bind, validate
[2] messages: used to provide error messages
[3] mapping: holding constraints, processors, and maybe child mapping, etc. used to validate/convert data, two types of mappings: field and group
[4] data: inputting data map

Check here and here for framework details.

binder bind method signature (return an Either and let user to continue processing):

//bind mappings to data, and return an either, holding validation errors (left) or converted value (right)
def bind[T](mapping: Mapping[T], data: Map[String, String], root: String = ""): Either[R, T]

binder validate method signature (validate only and not consume converted data):

//return (maybe processed) errors
def validate[T](mapping: Mapping[T], data: Map[String, String], root: String = "")

Check here for built-in mappings.

Extension Types:

(1) ErrProcessor: used to process error seq, like converting it to json
(2) PreProcessor: used to pre-process data, like omitting $ from $3,013
(3) Constraint: used to validate raw string data
(4) ExtraConstraint: used to validate converted value

* Check here for built-in PreProcessor/ErrProcessor.
**Check here for built-in Constraint/ExtraConstraint.

Options/Features:

  1. label: feature, readable name for current group/field
  2. mapTo: feature, map converted value to another type
  3. i18n: feature, labels starting with @ will be used as a message key to fetch a i18n value from messages
  4. eagerCheck: option, check errors as more as possible; default false, return right after a validation error found
  5. skipUntouched: option, skip checking untouched empty field/values; default false, won't skip untouched
  6. touchedChecker: function, check whether a field was touched by user; if yes, required fields can't be empty

p.s. for more dev and usage details, pls check the source codes and test cases.

How to

[TODO]

Build & Test

To hack it and make your contribution, you can setup it like this:

 $ git clone https://github.com/tminglei/form-binder.git
 $ cd form-binder
 $ sbt
...

To run the tests, pls execute:

 $ sbt test

Acknowledgements

License

The BSD License, Minglei Tu <[email protected]>

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].