Project

validaform

0.0
No commit activity in last 3 years
No release in over 3 years
Mount to an endpoint of your application, give it forms fields, and it'll return the validations errors/success in JSON. Really usefull when you want to add on-unblur or before-submit validations.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 5.1.1, ~> 5.1
 Project Readme

Validaform

Rails API form validator

Usage

Mount to an endpoint of your application, give it forms fields, and it'll return the validations errors/success in JSON. Really usefull when you want to add on-unblur or before-submit validations.

You post on /validaform/forms/validate a json with this format :

{
  fields: [
    { name: 'users/username', value: 'Asterixlegaulois' },
    { name: 'company/name', value: 'Panoracorp' }
  ]
}.to_json

and the API will send you the validation errors like

{
  fields:[
    {
      name: 'users/username',
      errors: ['too_long', 'too_great_album'],
      count: 2
    },
    {
      name: 'company/name',
      errors: ['taken'],
      count: 1
    }
  ],
  count: 3
}

example with curl =>

curl -X POST -H 'Content-Type: application/json' -d '{"fields":[{"name":"users/first_name","value":"Asterix"},  {"name":"users/last_name","value":"LeGaulois"}, {"name":"companies/size", "value":"17"}]}' http://localhost:3000/validaform/forms/validate

Installation

Add this line to your application's Gemfile:

gem 'validaform'

And then execute:

$ bundle

Or install it yourself as:

$ gem install validaform

Then at last, add mount Validaform::Engine, at: '/validaform' inside your Rails.application.routes.draw block of your route.rb

Contributing

TODO

-> Add tests

-> Check security

-> More explanations in README

Pull-requests

Please fork and make a pull-request, I'll be reactive.

License

The gem is available as open source under the terms of the MIT License.