Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Bootstrap static control from inside form #290

Merged
merged 2 commits into from
Aug 21, 2014
Merged

Use Bootstrap static control from inside form #290

merged 2 commits into from
Aug 21, 2014

Conversation

derpue
Copy link
Contributor

@derpue derpue commented Aug 14, 2014

Convenience stuff to define BS static form controls inside the forms creation.

This could of course all be done with fiddling in the template, rendering the form row-wise and using the twig form_control_static() function, but i'm often in the need to display one or more fields from my entity as static controls, and this let me do a simple {{ form(form, {'style': 'horizontal'}) }} in the template.

This patch consists of two commits which are independent from each other, just provide different ways and usages:

Extension

Provides for all fields which are rendered as form_widget_simple(date, time, datetime with 'widget' => 'single_text' set, number, integer, url, email) to be rendered as static control, using :

// simple field:
$builder->add('fieldname', 'number', array('static_control' => true));

// datetimefield with formatting:
$builder->add('updatedAt', 'datetime', array(
                'widget' => 'single_text',
                'static_control' => true,
                'format' => 'dd.MM.yyyy HH:mm:ss',
            ));

You should always set the field type explicitly instead of using autoguessing, which leads sometimes to extra attributes in the markup (eg maxlength) that break html validation.

Static control field type

Just another way to get a 'static control' rendered in the form:

// with a fields value (should be convertable to string):
$builder->add('fieldname', 'bs_static', $optionsIfNeeded);

// really static content
$builder->add('somenamenotafield', 'bs_static', array('mapped' => false, 'data'=> 'YourContentHere'));

// fields as datetime which need a Transformer (note the two `$builder->` calls):
$builder->add(
    $builder->create('updatedAt', 'bs_static', $optionsIdNeeded)
                 ->addViewTransformer(new DateTimeToStringTransformer(null, null, 'd.m.Y H:m:s'))
);

I'm not sure which one is the best to use, as both have advantages. Maybe just take both:)

And sorry for not providing tests, i still need to learn/understand that mockup stuff

@florianeckerstorfer florianeckerstorfer added this to the 2.2 milestone Aug 21, 2014
@florianeckerstorfer florianeckerstorfer merged commit 83bccc3 into braincrafted:develop Aug 21, 2014
@florianeckerstorfer florianeckerstorfer modified the milestones: 2.2, 2.1 Aug 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants