GithubHelp home page GithubHelp logo

dynamic-form-bundle's Introduction

Dynamic Form Bundle

Latest Stable Version License Build Status Scrutinizer Code Quality

Generates symfony forms based on YAML configuration files

Getting Started

This plugin requires Symfony 2.6.*

The recommended way to install Linio Dynamic Form Bundle is through composer.

{
    "require": {
        "linio/dynamic-form-bundle": "~1.0"
    }
}

Tests

To run the test suite, you need install the dependencies via composer, then run PHPUnit.

$ composer install
$ phpunit

Usage

Add the bundle on registerBundles() at AppKernel.php

new Linio\DynamicFormBundle\DynamicFormBundle();

The service dynamic_form.factory will be available.

Create your form on the Configuration File. The YAML structure for the Form should follow the next structure:

+---dynamic_form
|   \--- Form Name
|       \---Field Name
|           \---Field Options
|           \---Field Transformer
|           \---Field Validators

The method createform() takes the form configuration named new_user from app/config/config.yml.

use Linio\DynamicFormBundle\DynamicFormAware;

class TestController
{
	use DynamicFormAware;
	
	public function testAction()
	{
		$form = $this->getDynamicFormFactory()->createForm('new_user');
		return $this->render(
		  'WebBundle:Default:dynamicForms.html.twig',
		  ['form' => $form->createView(),]
		);
	}
}

The method getJsonConfiguration() takes the configuration from app/config/config.yml. and returns a JSON with the Form Configuration.

###Example Here's an example of a form named new_user with a single field called first_name:

dynamic_form:
    new_user:
        first_name:
            enabled: true
            type: text
            options:
                type: password
                required: true
            transformers:
            validators:

###Options Field options are the same as symfony, refer to the documentation

###Transformers

When using transformers write both the class where it is defined and the calls you need.

dynamic_form:
    new_user:
        first_name:
            enabled: true
            type: text
            transformer:
              class: 'Linio\Frontend\CustomerBundle\Form\DataTransformer\BornDateTransformer'
              calls:
                  - [setUserFormat, ['d/m/Y']]
                  - [setInputFormat, ['Y-m-d']]

###Validators

When using validators call each validator constraint and its parameters like shown down below.

dynamic_form:
    new_user:
        first_name:
            enabled: true
            type: text
            validation:
              'Symfony\Component\Validator\Constraints\True':
                  message: 'The token is invalid.'
              'Symfony\Component\Validator\Constraints\Length':
                  min: 2
                  max: 50

Release History

  • 2015-05-21   v1.0   First Version
  • 2015-06-11   v1.0.1   Updated getJsonConfiguration() so it can receive form name parameter

dynamic-form-bundle's People

Contributors

aramonc avatar fernandocarletti avatar israelliniomx avatar juliomz avatar klaussilveira avatar tavofuentes avatar

Watchers

 avatar  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.