Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cosmetic fix: Removed unnecessary attribute with default value from template #6153

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

Conversation

mweimerskirch
Copy link
Contributor

"1" is the default value of the "size" attribute for the "select" tag, so it is not necessary (=no backwards compatibility break).

Applying this patch makes it easier to work with bootstrap, because bootstrap includes a selector that checks it the "size" attribute is present: https://github.com/twitter/bootstrap/blob/master/less/forms.less#L172

I noticed the problem when working with the Sonata AdminBundle:

Before this patch:
patch-before

After this patch:
patch-after

The date and time fields in Sonata were not aligned because the CSS code between date and time fields was different (the size attribute was not present on date fields, only on time fields, so different CSS code was applied).

@fabpot
Copy link
Member

fabpot commented Dec 5, 2012

@bschussek any objections? Do you remember why it was done this way?

@stloyd
Copy link
Contributor

stloyd commented Jan 7, 2013

@bschussek ping =) (I can fix tests if you accept this =))

@webmozart
Copy link
Contributor

The problem here is when you use text widgets. These will be too wide unless you style them specifically.

What about passing "size" only if widget is text?

@webmozart
Copy link
Contributor

That indeed seems to be the solution. I didn't realize that "size" differs for the select and input tag:

select tag:

Defines the number of visible options in a drop-down list

input tag:

Specifies the width, in characters, of an element

Could you please adapt the PR?

@mweimerskirch
Copy link
Contributor Author

Shouldn't the size then be "2" for text-widgets? Otherwise there is not enough space for two-digit hours, minutes or seconds.

@webmozart
Copy link
Contributor

@mweimerskirch In theory yes, but in practice I found fields to be much wider than that. "1" was the value at which the field had the best look&feel.

@stloyd
Copy link
Contributor

stloyd commented Jan 7, 2013

IMO this is wrong that we force developers now to have defined look&feel, styling of fields etc., this should be always left for developers without forcing them to overwrite template block to simply (in this case) remove size="1" attribute.

@mweimerskirch
Copy link
Contributor Author

I tend to agree with @stloyd. However, this pull request is marked for 2.1. I feel that removing the size-attribute entirely might be a "compatibility" break. I've changed the pull request to keep the size-attribute for the text widget, while removing it for select widget. If it is to be removed entirely, I can create a second pull request for master.

@webmozart
Copy link
Contributor

@stloyd But we want to have a reasonable default, right? So far at least noone else complained. Furthermore, size="1" can be overwritten using CSS widths.

We can of course make the additional improvement by doing someting like

{"attr": {"size": attr.size|default("1")}}

Then the user can overwrite the size if required also via Twig if he prefers that over CSS.

@mweimerskirch
Copy link
Contributor Author

@bschussek: I don't see why to make this configurable. This would tempt devs to use an HTML attribute for styling instead of CSS.

IMHO the size=1 should be kept in sf 2.1 for the text widgets (but removed for the select) in order to prevent existing apps from breaking (as in this patch).
For 2.2 it should IMHO be removed entirely as this is the only place where HTML is used to predefine the style of a form element in the entire forms template.

fabpot added a commit that referenced this pull request Feb 22, 2013
This PR was merged into the 2.1 branch.

Commits
-------

b7bd630 [Form] Fixed TimeType not to render a "size" attribute in select tags

Discussion
----------

[Form] Fixed TimeType not to render a "size" attribute in select tags

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6153
| License       | MIT
| Doc PR        | -
@fabpot fabpot closed this Feb 22, 2013
nicolas-grekas added a commit that referenced this pull request Nov 24, 2021
… >= 3 (Staormin)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[String] Add conflict with symfony/translation-contracts >= 3

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Got the following issue this morning in symfony 5.4-RC1 with php 8.1:
```
!!
!!  Fatal error: Declaration of Symfony\Component\String\Slugger\AsciiSlugger::getLocale() must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::getLocale(): string in /opt/project/vendor/symfony/string/Slugger/AsciiSlugger.php on line 93
!!  Symfony\Component\ErrorHandler\Error\FatalError {#6153
!!    #message: "Compile Error: Declaration of Symfony\Component\String\Slugger\AsciiSlugger::getLocale() must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::getLocale(): string"
!!    #code: 0
!!    #file: "./vendor/symfony/string/Slugger/AsciiSlugger.php"
!!    #line: 93
!!    -error: array:4 [
!!      "type" => 64
!!      "message" => "Declaration of Symfony\Component\String\Slugger\AsciiSlugger::getLocale() must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::getLocale(): string"
!!      "file" => "/opt/project/vendor/symfony/string/Slugger/AsciiSlugger.php"
!!      "line" => 93
!!    ]
!!  }
!!
```
This PR fixed the error on my side.

Commits
-------

3b61236 [String] Add conflict with symfony/translation-contracts >= 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants