Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Do not put any empty div if label is disabled#19247
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Do not put any empty div if label is disabled#19247
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ae3f3e1 toaeb4de6Compare| {%else %} | ||
| col-sm-10 | ||
| {%endif %} | ||
| {%endspaceless %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You should use whitespace control modifiers instead of the spaceless tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@jvasseur fixed.
HeahDude commentedJun 30, 2016
Prettier than#18504, looks great! Maybe a test would be good. |
greg0ire commentedJun 30, 2016
This looks cleaner than having an empty div. |
soullivaneuh commentedJun 30, 2016
@HeahDude Do we have test suites on Symfony for templates? I would be glad to add some. Could you please indicate where to go? |
aeb4de6 toe4699e2CompareHeahDude commentedJun 30, 2016
| {%blockform_group_class -%} | ||
| col-sm-10 | ||
| {%iflabelissame as(false) -%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Isn't there a need for a minus sign before theif ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
No, there isn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks, just checking 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is needed for white-space control.
If I remove it, I get:
<divclass=" col-sm-12">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Oh you mean forblock! Indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ok you're right@greg0ire, should be:
{%-blockform_group_class -%} {%-iflabelissame as(false) -%}...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Are you sure ? minus for bothblock andif ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yes this happens in a string not at the start of a block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ok… anyway I think@soullivaneuh checks what this produces, so…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I did. And the actual state works correctly.
HeahDude commentedJun 30, 2016
There is alsohttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php but it should not be concerned here. Maybe it is :) |
soullivaneuh commentedJun 30, 2016
@HeahDude I added a test. Please tell me if it looks OK. |
830937e to66000e2Comparelyrixx commentedJun 30, 2016
It looks good to me. But if you can attach screenshot before / after in the PR description, it would be very nice. |
| $form =$this->factory->createNamed('name','date',null,array('label' =>false)); | ||
| $view =$form->createView(); | ||
| $this->renderWidget($view); | ||
| $html =$this->renderLabel($view); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Consider not using the$form and$html OTVs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Can be inlined inassertEmpty()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This was just a copy paste of a similar test.
soullivaneuh commentedJun 30, 2016
@lyrixx I updated the PR body. 👍 Note: We can have one edge case AFAIK: ->add('test', TextType::class, ['mapped' =>false,'label' =>false,'attr' => ['placeholder' =>'My label goes here', ]]) Renders: I think this case is very rare comparing to the other, but can still happen. Maybe could we have an |
| col-sm-10 | ||
| {%-endblockform_group_class %} | ||
| {%blockform_group_class %} | ||
| {%iflabelissame as(false) -%} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
missing whitespace control here to remove the indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You mean{%- if?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Indeed, good catch!
soullivaneuh commentedJun 30, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Also maybe we should create a new block for the form-group class? Because ATM, user will have to copy/paste the whole logic if they want to change it: {%blockform_group_class %} {%iflabelis notsame as(false) -%} col-md-9 {%-else -%} col-md-12 {%-endif %}{%endblockform_group_class %}Or maybe a |
jongotlin commentedJul 1, 2016
My two cents..
Can confirm the form I used in my pr looks the same with this code. 👍 |
soullivaneuh commentedJul 1, 2016
The Consider this as a row for a form. AFAIK, we can make them nested.
Please see#19247 (comment). |
jongotlin commentedJul 1, 2016
We're solving two different thing here. Collections and nested forms. Consider my nested form type the Form from my pr <divclass="form-group"><divclass="col-sm-12"><divid="foo_foo2"><divclass="form-group"><labelclass="col-sm-2 control-label required"for="foo_foo2_child">Child</label><divclass="col-sm-10"><inputtype="text"id="foo_foo2_child"name="foo[foo2][child]"required="required"class="form-control"/></div></div></div></div></div> When rendering the collection type I see the need for it. Is there a way to know the difference between them? Regarding BC-breaks. Yes, that comment is what I was thinking of. I don't think we should change the behavior and render the input the whole width. |
soullivaneuh commentedJul 1, 2016
You mean about: <divclass="form-group"><divclass="col-sm-12"> ? I don't see the issue. This is like having a |
jongotlin commentedJul 1, 2016
soullivaneuh commentedJul 1, 2016
The code would be a lot complexified, not sure it worth it just for an esthetic case... @lyrixx Could we please have your opinion for this and#19247 (comment)? |
jongotlin commentedJul 1, 2016
Agreed! I'm more concerned about the BC-break. |
| {%blockform_group_class -%} | ||
| col-sm-10 | ||
| {%-endblockform_group_class %} | ||
| {%blockform_group_class %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
missing space control at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Space control added.
| publicfunctiontestLabelNoDivIfFalse() | ||
| { | ||
| $this->assertEmpty( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Maybe you could use a consistent style here:
$view =$this->factory->createNamed('name','date',null,array('label' =>false))->createView();$this->assertEmpty($this->renderLabel($view),'The label should not be rendered');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I honestly don't see the interest. You create a variable that will be used only once.
Why not simply pass the result to the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I second that. Seemore information about thoughtless one-time variables here. Note that OTVs can be used to break down complicated expressions, but I personally don't feel this is complicated enough to warrant an OTV.
If you need the variable because it clarifies things, maybe consider using a comment instead, you can even write whole sentences with them.
fabpot commentedSep 14, 2016
@soullivaneuh Looks like there aren't that many things to do to finish this one, can you have a look at the latest comments? Thanks. |
This produces wrong alignments especially for form collections.
soullivaneuh commentedSep 15, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@fabpot I corrected the review and answered for this one:#19247 (comment) Also I think I could add a commit to improve a little the process. IMHO, we should introduce some new blocks:
With the current state of this PR, if we want to change the col classes like this: {%use'bootstrap_3_horizontal_layout.html.twig' %}{%blockform_label_class -%} col-sm-3{%-endblockform_label_class %}We will have a broken form like this: So we have to override {%blockform_group_class -%} {%-iflabelissame as(false) -%} col-sm-12 {%-else -%} col-sm-9{# This is the ONLY real override here#} {%-endif -%}{%-endblockform_group_class %}If we have the two blocks I proposed, this will just looks like this (final state): {%use'bootstrap_3_horizontal_layout.html.twig' %}{%blockform_label_class -%} col-sm-3{%-endblockform_label_class %}{%blockform_group_with_label_class -%} col-sm-9{%-endblockform_group_with_label_class %}What do you think? Maybe we can find a simplier solution for block name, I waiting your feedbacks for that. But I think we really should avoid the ugly copy/paste constraint. |
2c059f2 to6efc6b2Comparejaviereguiluz commentedNov 7, 2016
@soullivaneuh would it make sense to only introduce a new block called |
soullivaneuh commentedJun 27, 2017
Sorry guys, but I don't have any more time to work on this PR right now. I allowed edit from maintainer, if anyone want to continue it. |
fabpot commentedJul 6, 2017
@javiereguiluz@HeahDude Can you take over this one? Or anyone else wanting to take over? |
fabpot commentedOct 1, 2017
Closing as there is apparently nobody wanting to take over this PR. Feel free to reopen. |




Uh oh!
There was an error while loading.Please reload this page.
This produces wrong alignments especially for form collections.
This PR is an alternative to#18504, fixing both#18850 and#18474 issues.
@lyrixx what do you think of this? Maybe I'm forgetting some edge cases, please tell me so we can discuss about it! 👍
cc@jongotlin
Application
With the following form type configuration:
The actual rendering looks like this:
Thanks to this PR, it's now: