GithubHelp home page GithubHelp logo

giovannialbero1992 / jsformvalidatorbundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from formapro/jsformvalidatorbundle

0.0 2.0 0.0 631 KB

The Javascript validation for Symfony 2 and 3 forms

License: MIT License

PHP 64.17% JavaScript 27.19% HTML 8.43% Smarty 0.05% Shell 0.16%

jsformvalidatorbundle's Introduction

FpJsFormValidatorBundle

Build Status Total Downloads

This module enables validation of the Symfony 3 forms on the JavaScript side. It converts form type constraints into JavaScript validation rules.

If you have Symfony 2.8.* or 2.7.* - you need to use Version 1.3.* If you have Symfony 2.6.* or less - you need to use Version 1.2.*

1 Installation

1.1 Download FpJsFormValidatorBundle using composer

Run in terminal:

$ php composer.phar require "fp/jsformvalidator-bundle":"dev-master"

Or if you do not want to unexpected problems better to use exact version.

$ php composer.phar require "fp/jsformvalidator-bundle":"v1.4.*"

1.2 Enable the bundle

Enable the bundle:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Fp\JsFormValidatorBundle\FpJsFormValidatorBundle(),
    );
}

1.3 Enable javascript libraries

<html>
    <head>
        {{ include('FpJsFormValidatorBundle::javascripts.html.twig') }}
    </head>
    <body>

    </body>
</html>

1.4 Add routes

If you use the UniqueEntity constraint, then you have to include the next part to your routing config: app/config/routing.yml

# ...
fp_js_form_validator:
    resource: "@FpJsFormValidatorBundle/Resources/config/routing.xml"
    prefix: /fp_js_form_validator

Make sure that your security settings do not prevent these routes.

2 Usage

After the previous steps the javascript validation will be enabled automatically for all your forms.

  1. Disabling validation
  2. If your forms are placed in sub-requests
  3. If you need to initialize JS validation for your forms separately, or by some event, in this case you need to follow these steps instead of the chapter 1.3

3 Customization

Preface

This bundle finds related DOM elements for each element of a symfony form and attach to it a special object-validator. This object contains list of properties and methods which fully define the validation process for the related form element. And some of those properties and methods can be changed to customize the validation process.

If you render forms with a some level of customization - read this note.

  1. Disable validation for a specified field
  2. Error display
  3. Get validation groups from a closure
  4. Getters validation
  5. The Callback constraint
  6. The Choice constraint. How to get the choices list from a callback
  7. Custom constraints
  8. Custom data transformers
  9. Checking the uniqueness of entities
  10. Form submit by Javasrcipt
  11. onValidate callback
  12. Run validation on custom event
  13. Collections validation

jsformvalidatorbundle's People

Contributors

66ton99 avatar sustmi avatar asentner avatar manuelj555 avatar tools4origins avatar hanneskaeufler avatar benr77 avatar maryo avatar vaclavsir avatar maarekj avatar

Watchers

James Cloos avatar Giovanni Albero avatar

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.