Skip to content

No Bootstrap markup is rendered for label set as false #18504

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

Closed
wants to merge 1 commit into from
Closed

No Bootstrap markup is rendered for label set as false #18504

wants to merge 1 commit into from

Conversation

jongotlin
Copy link
Contributor

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? -
Fixed tickets #18474
License MIT
Doc PR

When using horizontal Bootstrap forms and setting 'label' => false for a custom form type the form_row renders an ugly markup
screenshot 2016-04-11 13 48 25

This pr fixes that and make the form look like this
screenshot 2016-04-11 13 45 05

// FooType
$builder
    ->add('test', 'text')
    ->add('foo', new BarType())
    ->add('foo2', new BarType(), ['label' => false])
;
// BarType
$builder->add('child', 'text');

<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
{{- form_errors(form) -}}
{% set displayMarkup = form.children|length == 0 or form.vars.label is not same as(false) %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not change the behavior when form.children|length == 0 imo.
This is not a bug, other templates show the label, and may be part of the work in progress feature in #17609.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a bug displaying a form-group inside a form-group. The label i still shown - the markup is not rendered when the label is set to false.
I cannot see how this will be solved in your pr. It looks like another feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I misread the condition, IIUC you force the label (even false) to be printed when there is no child.
So I guess this should be right.

@fabpot
Copy link
Member

fabpot commented Jun 14, 2016

LGTM.

@jongotlin Can you add some tests to ensure that we don't break this again in the future?

@HeahDude
Copy link
Contributor

Ref #18850.

@soullivaneuh
Copy link
Contributor

@jongotlin Did you check your PR respect the second sample of #18850 (comment)?

->add('test', TextType::class, [
    'mapped' => false,
    'label' => false,
    'attr' => [
        'placeholder' => 'My label goes here',
    ]
])

image

@soullivaneuh
Copy link
Contributor

Also:

But in any case, this should not be handled like this IMHO but with a col-*-offset.

@soullivaneuh
Copy link
Contributor

This does not see my issue. I download your patch and tried with this form config:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('domain', null, [
            'label' => 'ssl_certificate.form.domain',
            'translation_domain' => 'front',
        ])
        ->add('subdomains', CollectionType::class, [
            'label' => 'ssl_certificate.form.subdomains',
            'translation_domain' => 'front',
            'type' => TextType::class,
            'allow_add' => true,
            'allow_delete' => true,
            'prototype' => true,
            'options' => [
                'label' => false,
                'text_suffix' => '',
                'attr' => [
                    'class' => 'subdomain-domain',
                ],
            ],
        ])
    ;
}

Result:

image

This solve not this issue: #18850 (comment)

@soullivaneuh
Copy link
Contributor

Or the issue is not really related and in this case #18850 should be re-opened.

@soullivaneuh
Copy link
Contributor

Please see this alternative: #19247

@jongotlin
Copy link
Contributor Author

Thanks @soullivaneuh. I didn't think of the CollectionType-example you provided. I'll look into how it can be solved.

@jongotlin
Copy link
Contributor Author

Not sure how to solve @soullivaneuh s issue. I guess also the prototype is affected. Anyone having an idea where to start?

@soullivaneuh
Copy link
Contributor

@jongotlin I check vertical form, I have no issue about this at all.

The only solution I found is to correct the column classes in #19247.

@fabpot
Copy link
Member

fabpot commented Jul 28, 2016

Closing in favor of #19247

@fabpot fabpot closed this Jul 28, 2016
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.

5 participants