Giter VIP home page Giter VIP logo

formjsvalidationbundle's Introduction

ACSEO Form JS Validation Bundle

A bundle that add js validation to you forms

Installation

  1. Install using composer
composer require acseo/form-js-validation-bundle
  1. Update AppKernel.php :
<?php
// app/AppKernel.php
class AppKernel extends Kernel
{
	public function registerBundles()
    {
        $bundles = [
        // ...
        new ACSEO\Bundle\FormJsValidationBundle\ACSEOFormJsValidationBundle(),
        // ...
  1. Select your js validation plugin between validation.io and jqueryvalidation.org in the parameters.yml :
// app/config/parameters.yml

parameters:
    // ...
    // to use the validation.io
    acseo_form_js_validation.service: acseo_form_js_validation_io
    // or to use the jqueryvalidation.org
    acseo_form_js_validation.service: acseo_form_jquery_form_validator

Usage

Add Form validation to your form

In your controller, add js form validation :

<?php
//...
public function newAction(Request $request)
{
    // ...
    $awesomeEntity = new AwesomeEntity();
    $form   = $this->createForm(AwesomeEntityType::class, $awesomeEntity,array(
        'action' => $this->generateUrl('awesomeentity_new'),
        'method' => 'POST')
    );

    // ...
    $form = $this->get("acseo_form_js_validation.service")->addJsValidation($form);
    // ...

Update templates

Using form validation.io

  1. In your base template, use formvalidation js and css : http://formvalidation.io/getting-started/#usage

  2. In the template when the form is used, just update the code with this :

<!-- new.html.twig -->

{{ form_start(form, {'attr': { 'id' : 'awesome_entity_form', 'data-fv-framework' : 'bootstrap', }}) }}

<!-- display your form here -->

{{ form_end(form)}}

<script type="text/javascript">
$(document).ready(function() {
   $('#awesome_entity_form').formValidation();
});
</script>

Using form jqueryvalidation.org

  1. In your base template, use jqueryvalidation js and css : https://github.com/jquery-validation/jquery-validation/releases

  2. In the template when the form is used, just update the code with this :

<!-- new.html.twig -->

{{ form_start(form, {'attr': {'id': 'awesome_entity_form'}}) }}

<!-- display your form here -->

{{ form_end(form)}}

<script type="text/javascript">
$(document).ready(function() {
   $('#awesome_entity_form').validate();
});
</script>

formjsvalidationbundle's People

Contributors

npotier avatar romainguerrero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

agepartnership

formjsvalidationbundle's Issues

Internationalize date validation

Hello @romainguerrero. Thanks for your amazing work on this bundle, its really awesome to be able to validate symfony forms with javascript.

I've noticed that date format check is only for french format :

"data-rule-dateITA" => 'true', // use dateITA to get french format (dateFR is not implemented yet)

it would be great to get the current locale from the translator service (http://api.symfony.com/2.8/Symfony/Component/Translation/Translator.html#method_getLocale) to determine how to check the date format, or at least make the format configurable.

I would be please to help on this feature.

Symfony 4?

Hi, are you planning an update for symfony 4 ? thanks for you work ;-)

SF5 ?

Hi, are you planning an update for symfony 5 ?
Thanks for you work ;-)

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.