Code Monkey home page Code Monkey logo

adamquailefieldsetbundle's People

Contributors

abm-dan avatar adamquaile avatar asentner avatar dcarbone avatar tacman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

adamquailefieldsetbundle's Issues

Unable to target child form elements with $form->get()

Not sure if this is a bug, or me going about things the wrong way, but as I understand it; when you want to target a form element you can use $form->get(field_name) - where "$form" is the Form object created by Controller->createForm($type, $entity).

I can target anything that is added directly though FormBuilderInterface->add(name, type, options) but If I try to target anything that is a child of a fieldset created with this bundle (using the same string as set in the fieldset[options][fields][name] variable), symfony throws an error of "Child "field_name" does not exist.

Is this a limitation of the FieldsetBundle, or an example of my ignorance of Symfony's methods?
How can I access the underlying object for the child element?

Overwrite template

Could you change the bundle so overwriting the fieldset_widget in a custom fields.html.twig works?

That file can be set in config.yml:

# Twig Configuration
twig:
    form:
        resources:
            - ':Form:fields.html.twig'

Now, I have to copy fieldset.html.twig to /app/Resources/AdamQuaileFieldsetBundle/views/Types/fieldset.html.twig

I believe it's better to follow the structure shown on http://symfony.com/doc/current/cookbook/form/create_custom_field_type.html and https://gist.github.com/spcmky/8512371

Make 'constraints' possible for form without class

I have a form without a class in which I add a fieldset with fields that need to be validated. The following form only validates the field customer_address

<?php

namespace My\NiceBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
 */
class ContactController extends Controller
{

    /**
     */
    public function indexAction(Request $request)
    {
        $defaultData = array();
        $form = $this->createFormBuilder($defaultData,
            array(
                'translation_domain' => 'form',
                'attr' => array(
                    'novalidate' => 'novalidate' // Disable HTML5 validation for testing server validation.
                ),
            ))
            ->add('customer_address','choice',array(
                'multiple' => false,
                'required' => true,
                'empty_value' => '',
                'attr'   =>  array(
                    'class'   => 'chosen large'
                ),
                'constraints' => new NotBlank()
            ))
            ->add('contact', 'fieldset', array(
                'label' => false,
                'legend' => 'fieldset.contact',
                'fields' => array(
                    array(
                        'name' => 'email-address',
                        'type' => 'email',
                        'attr' => array(
                            'label' => 'input.email-address',
                        ),
                'constraints' => new NotBlank()
                    ),
                    array(
                        'name' => 'username',
                        'type' => 'text',
                        'attr' => array(
                            'label' => 'input.username',
                        ),
                    ),
                    array(
                        'name' => 'message',
                        'type' => 'textarea',
                        'attr' => array(
                            'label' => 'input.message',
                        ),
                        'constraints' => new NotBlank(),
                    ),
                ),
                'constraints' => new NotBlank(),
            ))
            ->add('button', 'fieldset', array(
                'label' => false,
                'legend' => '',
                'fields' => array(
                    array(
                        'name' => 'send-email',
                        'type' => 'submit',
                        'attr' => array(
                            'label' => 'button.send',
                        ),
                    ),
                ),
            ))
            ->getForm();

        $form->handleRequest($request);

        if ($form->isValid()) {
            $data = $form->getData();
        }

        return $this->render('MyNiceBundle:Contact:index.html.twig', array('form' => $form->createView()));
    }

}

How can I add the 'constraints' to the fields in the fieldset so it works?

NB The form is rendered in twig with:

{{ form(form) }}

Could not load type "fieldset"

Hi,

I just installed and followed your directions to implement fieldsets on a Symfony 3.3 version and I get stuck with the "Could not load type "fieldset"" error.

Here are my log:
`Symfony\Component\Form\Exception\InvalidArgumentException:
Could not load type "fieldset"

at vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php:87
at Symfony\Component\Form\FormRegistry->getType('fieldset')
(vendor\symfony\symfony\src\Symfony\Component\Form\FormFactory.php:74)
at Symfony\Component\Form\FormFactory->createNamedBuilder('my_group_example_one', 'fieldset', null, array('label' => false, 'legend' => 'Your fieldset legend', 'fields' => object(Closure)))
(vendor\symfony\symfony\src\Symfony\Component\Form\FormBuilder.php:106)
at Symfony\Component\Form\FormBuilder->create('my_group_example_one', 'fieldset', array('label' => false, 'legend' => 'Your fieldset legend', 'fields' => object(Closure)))
(vendor\symfony\symfony\src\Symfony\Component\Form\FormBuilder.php:269)
at Symfony\Component\Form\FormBuilder->resolveChildren()
(vendor\symfony\symfony\src\Symfony\Component\Form\FormBuilder.php:215)
at Symfony\Component\Form\FormBuilder->getForm()
(vendor\symfony\symfony\src\Symfony\Component\Form\FormFactory.php:30)
at Symfony\Component\Form\FormFactory->create('NewsletterBundle\Form\EmailType', object(Email), array())
(vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait.php:331)
at Symfony\Bundle\FrameworkBundle\Controller\Controller->createForm('NewsletterBundle\Form\EmailType', object(Email))
(src\NewsletterBundle\Controller\NewsletterController.php:33)
at NewsletterBundle\Controller\NewsletterController->indexAction(object(Request))
at call_user_func_array(array(object(NewsletterController), 'indexAction'), array(object(Request)))
(vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:153)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:68)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php:171)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(web\app_dev.php:29)
at require('S:\htdocs\4.TMP\newsletter\web\app_dev.php')
(vendor\symfony\symfony\src\Symfony\Bundle\WebServerBundle\Resources\router.php:42)`

Any clue on how to make it work ?

"Choice" options are empty

Hey, I've got a problem similar to issue #4; I can't get select boxes to render their content, and I can't work out why.
I've triple checked the format (as per the other issues resolution) and unless I'm being blind, I can't see anything wrong with it.

The options I'm passing to $buider->add() are as follows:

$builder->add(
    'applicant_details',
    'fieldset',
    array(
        'label'  => false,
        'legend' => 'Your Details',
        'fields' => array(
            array(
                'name' => 'title',
                'type' => 'choice',
                'attr' =>  array(
                    'label'   => 'Title',
                    'choices' => array(
                        'Mr'   => 'Mr',
                        'Mrs'  => 'Mrs',
                        'Miss' => 'Miss',
                        'Ms'   => 'Ms',
                        'Mx'   => 'Mx',
                    ),
                ),
            ),
        ),
    )

Can anyone see where I'm going wrong?

Newest build caused UndefinedOptionsException for "fields" and "legend"

The options "fields", "legend" do not exist. Known options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "help", "inherit_data", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "max_length", "method", "pattern", "post_max_size_message", "property_path", "read_only", "required", "translation_domain", "trim", "validation_groups", "virtual".
500 Internal Server Error - UndefinedOptionsException

Reverting back to cd1e383 fixes the error.

This error happens when I set the fields or legend variable here:
$builder->add('general', 'fieldset', array(
'label' => false,
'legend' => 'General',
'fields' => array(
array(
'name'=>'name',
'type'=>'text',
'attr'=> array(
'label' => 'entry_name',
'constraints' => array(
new NotBlank(),
new Length(array(
'min' => 3,
'max' => 255
)),
)
)
),

....... and so on.

Did I miss something?

Problem with Symfony 6.1.2

When I tried to use with new symfony versions (I use 6.1.2) got an:
Unable to find template "AdamQuaileFieldsetBundle:Types:fieldset.html.twig" (looked into: C:\domains\my-project/templates, C:\domains\my-project\vendor\symfony\twig-bridge/Resources/views/Form)

Is it possible to update for new versions?

Automatic translation of legends

I have a form to which I pass a translation_domain as parameter.

Am I missing something or could it truely be that the legend titles won't be translated automatically?

Choice field does not render choices

$builder
            ->add(
                'program_group',
                'fieldset',
                [
                    'label'  => false,
                    'legend' => 'Program details',
                    'fields' => [
                        [
                            'name'    => 'name',
                            'type'    => 'choice',
                            'attr'    => ['label' => false],
                            'expanded'  => true,
                            'multiple'  => true,
                            'choices' => [
                                'Analytical'                            => 'Analytical',
                                'Human Resources'                       => 'Human Resources',
                                'Government Communication Service'      => 'Government Communication Service',
                                'Northern Ireland'                      => 'Northern Ireland',
                                'Generalist'                            => 'Generalist',
                                'Commercial and Finance'                => 'Commercial and Finance',
                                'Digital and Technology'                => 'Digital and Technology',
                                'European'                              => 'European',
                                'Summer Diversity Internship Programme' => 'Summer Diversity Internship Programme',
                                'Early Diversity Internship Programme'  => 'Early Diversity Internship Programme',
                            ],
                        ],
                    ]
                ]
            );

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.