Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[WIP] [3.2] [Form] add 'empty_view' option in FormType#17609

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

Conversation

@HeahDude
Copy link
Contributor

@HeahDudeHeahDude commentedJan 30, 2016
edited
Loading

QA
Bug fix?yes
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#17579,#18804
LicenseMIT
Doc PRtodo
  • Gather feedback
  • Use translation for default message
  • Add some tests
  • Update foundation 5 theme
  • Make tests pass
  • Add missing translations
  • Doc PR

Theempty_view option can be astring, or aboolean. By default it is'No field' when compound andfalse otherwise. It uses thetranslation_domain option for its translation.

CollectionType inherits it but this can be avoid be settingempty_view tofalse.

Theempty_view is defined inFormType::finishView() and overriden inChoiceType::finishView() to be defined whenchoices andpreferred_choices view vars are empty.

In the templates, the old behaviour is kept explicitly set tofalse.

So 2 ways of using it:

  • passing a translatable simple string to custom a message instead of an emptydiv or an emptyselect input :
// src/AppBundle/Form/Type/TenantType.php// ...$builder->add('cars', \Symfony\Bridge\Doctrine\Form\Type\EntityType::class,array('class' => \AppBundle\Entity\Cars::class,'empty_view' =>'No cars available',// will be escaped// ...));
  • overriding theempty_row to use customhtml :
{# 'default/rent_a_car.html.twig#}{# ...#}{%form_theme_self %}{%block'empty_row' %}{# custom html with access to 'full_name', 'attr', and 'empty_view' view vars#}{%endblock %}{{ form(form) }}

What do you think ?

Copy link
Member

Choose a reason for hiding this comment

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

looks like the whitespace control changes are unrelated to this feature and should be done in a different PR

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@xabbuh I did this to match bootstrap layout. DYTH that it needs a PR ?

Copy link
Member

Choose a reason for hiding this comment

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

Well, I think there's now use in having this different in 2.8/3.0.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@xabbuh I don't understand your comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

@HeahDude it's not related to this PR so should be done in a separate one. It should also be done on the latest branch this layout is available, to ease future merging.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@jakzal ok reverted.foundation_5_layout was introduced on 2.8 should I make a PR on this branch or on master ? Do you think it's really needed ?

@xabbuh
Copy link
Member

Status: Needs work

@HeahDude
Copy link
ContributorAuthor

@xabbuh thanks for the review.

This PR is a POF to see if symfony deciders agree with this way of fixing#17579, I added your suggestion in the todo list of the description.

}

// Provide a default message when choices var is empty
if (empty($view->vars['choices']) &&$options['expanded']) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove thisif completely. Its up to the template to decided what to display and when.
At least I would remove the check forexpanded since one could decide to display a message insteadof an empty select box.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@backbone87 👍 for removing the expanded condition.

But I don't think it's worth init a view varempty_choices and add it to the context ifchoices are not empty.

@HeahDudeHeahDudeforce-pushed thefeature-choice_type_option-empty_choices branch fromd132bbe to18fd85eCompareFebruary 16, 2016 03:47
@HeahDudeHeahDude changed the title[WIP] [3.1] [Form] better handling empty choices in ChoiceType when expanded[WIP] [3.1] [Form] add 'empty_choices' option in ChoiceTypeFeb 16, 2016
<?phpecho$view['form']->block($form,'choice_widget_collapsed')?>
<?phpendif?>
<?phpelse:?>
<?phpif ('' ===$empty_choices) {
Copy link
Member

Choose a reason for hiding this comment

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

$empty_choices isn't set here (otherwise the block above would have been executed).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

right, the condition on the first line is wrong, it should be :
+<?php if (!isset($empty_choices)): ?>

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@xabbuh thanks, fixed.

@HeahDude
Copy link
ContributorAuthor

Work is still in progress, but I've updated the description and refactored a bit in the last commit.

Status: Needs Review

@HeahDude
Copy link
ContributorAuthor

I've got a suggestion as there is here an addition of a new default translation domain, may be it would be nice to translate the'None' default placeholder too (seehttps://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L283).

Do you agree with this handling ?
If so, may I add this in that PR (in a separated commit) or send another one if this one gets merged ?

<body>
<trans-unit id="1">
<source>No choice available</source>
<target><em>No choice available.</em></target>
Copy link
Contributor

Choose a reason for hiding this comment

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

Either the em-tag should be put in the correct xmlns or the whole content of target should be marked CDATA

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@backbone87, thanks for the review, I've just copy-pastedvalidators.en.xliff as I'm not familiarized with this format, could you please precise ?

Copy link
Contributor

Choose a reason for hiding this comment

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

its nothing specific to xliff. its about how xml namespaces work. when an xml parser parses the given xliff xml file, it interprets the em-element to be part of the xliff namespace (which is declared as the "default" namespace in the given document withxmlns="urn:oasis:names:tc:xliff:document:1.2"). This isnt a problem, unless the xliff consumer doesnt know what todo with an em-element. But xsd validation against the xliff schema will most likely fail (because it probably didnt define an em-element).

One way is to declare the xhtml namespace in the document ´xmlns:xh="http://www.w3.org/1999/xhtml"` and qualify the em-element against it:<xh:em>...</xh:em>.http://www.w3.org/1999/xhtml is used for xhtml 1.x and xml serialisation of html5 (xhtml5).

But since we dont care for the structure of the content in this use case, because the translation consumer expectstext/plain produced by xliff, we can just properly escape the content of the target-element. either with<target>&lt;em&gt;No choice available.&lt;/em&gt;</target> or (more readable)<target><![CDATA[<em>No choice available.</em>]]></target> (cdata = character data)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@backbone87 Thank you very much for this explanation :)

@webmozart
Copy link
Contributor

I think it's a good idea to add this functionality in general. When choices are loaded from a data source and no choice is available, displaying some text instead seems like the proper thing to do.

I'm not happy with the naming though. "empty", in the sense of a choice field, refers to the "empty choice", i.e. the choice that is selected ifno choice is selected. Using the same terminology creates ambiguity and potentially confuses our users. Unfortunately I can't think of a better name at the moment.

@HeahDude
Copy link
ContributorAuthor

@webmozart, I proposedempty_form if this should be a global option for compound form types which would be inherited byChoiceType (andCollectionType) in#17579 (comment).

We could add a default normalizer at the root definition for more safety to no use it whencompound isfalse, but depending on the implementation it might just be ignored in that case.

@webmozart
Copy link
Contributor

Even thenempty is a problematic term. "Empty" - so far - refers to thevalue of a field. A field/form is empty if that value isnull or''.

You are introducing a different concept of "empty", namely that a form is empty if doesn't contain children. Now it could happen that an empty form (your definition: no children) is not empty (existing definition: data is notnull). Do you see how this can be ambiguous and confusing?

I think we need to find another name that does not involve the word "empty".

@HeahDude
Copy link
ContributorAuthor

@webmozart, I've kept working in this, and did not use that idea but another one also with "empty"...

While implementing it globally, it felt more natural to useempty_view because actually it's the compound container block (HTML tag) which is empty and I found it makes a good echo toempty_data while keeping it clear that the value must be a string.

What aboutno_child_view orempty_compound ?

I just need to fix some tests with table layout and I will push everything.

@HeahDudeHeahDude changed the title[WIP] [3.1] [Form] add 'empty_choices' option in ChoiceType[WIP] [3.1] [Form] add 'empty_view' option in FormTypeMar 25, 2016
@HeahDude
Copy link
ContributorAuthor

Updated title and description accordingly.

<body>
<trans-unit id="1">
<source>No choice available</source>
<target>![CDATA[<em>Aucun choix n'est disponible.</em>]]</target>
Copy link
Contributor

Choose a reason for hiding this comment

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

the cdata tags have syntax errors. correct is:<![CDATA[ and]]> (not escaped)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@backbone87 thanks, I will update it.

@HeahDude
Copy link
ContributorAuthor

I'm actually still stuck on that test:

1) Symfony\Bridge\Twig\Tests\Extension\FormExtensionDivLayoutTest::testEmptyCollectionFailed asserting that /div    /em[.="[trans]No fields[/trans]"]    [@id="my&id"]    [@class="my&class"]    [count(./div)=0]/following-sibling::input[@type="hidden"][@id="names__token"]matches exactly once. Matches 0 times in <div>        <em>[trans]No fields[/trans]</em>    </div><input type="hidden" name="names[_token]">/Users/Heah/Sites/dev/symfony/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php:84/Users/Heah/Sites/dev/symfony/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php:106/Users/Heah/Sites/dev/symfony/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php:338

Does anyone know what I need to fix here ? :(

@HeahDudeHeahDudeforce-pushed thefeature-choice_type_option-empty_choices branch fromf68e1e0 to94f2a70CompareMarch 30, 2016 17:21
@HeahDude
Copy link
ContributorAuthor

Rebased.

@HeahDude
Copy link
ContributorAuthor

ping@webmozart :) There is no rush to merge any of my PR, we should polish anything but I can't go further for now without your review I guess.

Actually I've got three path tests failing on this one, and I can't make them pass...

{%-setattr=attr|merge({class: (attr.class|default('') ~' form-control')|trim}) %}
<div {{block('widget_container_attributes') }}>
<p>
<em>{{-translation_domainissame as(false)?empty_view:empty_view|trans({},translation_domain) -}}</em>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why<em>? I think we should refrain from adding styling as much as possible.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

OK

Copy link
Contributor

Choose a reason for hiding this comment

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

em isnt about styling? its about emphasis. and because there is no form, that one might expect, you put the emphasis on the presented message, probably giving reasons as forwhy there are no children.

HeahDude reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I agree, I did not even think about it when I added it naturally.

Because, it may be unexpected to see that string standing for a missing expectation.

Theemphasis clearly mark the informational sense of such string IMHO.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we should leave that decision up to the developer. We never made such assumptions in any other part of form themes.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Fair enough then :)

@HeahDude
Copy link
ContributorAuthor

Status: needs work

@HeahDudeHeahDude changed the title[WIP] [3.1] [Form] add 'empty_view' option in FormType[WIP] [3.2] [Form] add 'empty_view' option in FormTypeApr 28, 2016
@nicolas-grekasnicolas-grekas added this to the3.x milestoneDec 6, 2016
@nicolas-grekas
Copy link
Member

ping@HeahDude, status of this PR considering feat. freeze?

@nicolas-grekasnicolas-grekas modified the milestones:3.4,4.1Oct 8, 2017
@fabpot
Copy link
Member

@HeahDude Do you think you can work on finishing this PR or shall we close it?

@fabpot
Copy link
Member

Closing this PR as there is no more activity.@HeahDude Feel free to reopen whenever you have time to finish it. Thanks.

@fabpotfabpot closed thisMar 31, 2018
@lukepass
Copy link

Hello, sorry for reopening this one but I had a problem today with an empty CollectionType and I had to manually set setRendered in order to avoid the empty template. Is there another way to fix it?

Thanks!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

9 participants

@HeahDude@xabbuh@webmozart@backbone87@nicolas-grekas@fabpot@lukepass@jakzal@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp