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

[Form] Fixed DateType format option for single text widget#21063

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

Merged
fabpot merged 1 commit intosymfony:2.7fromHeahDude:fix/datetime_type-format
Feb 4, 2017

Conversation

@HeahDude
Copy link
Contributor

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets~
LicenseMIT
Doc PR~

It's currently not possible to use a custom format withDateType when not using one of the three values day, month or year (i.e in my case "MM/yyyy").

The formatter handles it, it looks like this option check is wrong, this PR fixes it.

yceruto reacted with thumbs up emoji
$this->factory->create('date',null,array(
'months' =>array(6,7),
'format' =>'yy',
'format' =>'wrong',
Copy link
Member

Choose a reason for hiding this comment

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

You will now have to change the name of the method.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I didn't change it on purpose as this is aboutand butor was previously tested. Should I change it anyway?

@xabbuh
Copy link
Member

But what is the expected value for the omitted parts of the date?


$form->submit('2010');

$this->assertDateTimeEquals(new \DateTime('2010-01-01 UTC'),$form->getData());
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@xabbuh The expected value for day and month is tested here with first of each. For the year I'd say that the default is the current but I can add a test for it.

Copy link
Member

Choose a reason for hiding this comment

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

I am not convinced that this really is a bug fix. IMO being able to omit parts of a date is a new feature and you should then also be able to configure the values of the omitted parts.

yceruto reacted with thumbs up emoji
$this->factory->create('date',null,array(
'months' =>array(6,7),
'format' =>'yy',
'format' =>'wrong',
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I didn't change it on purpose as this is aboutand butor was previously tested. Should I change it anyway?

@yceruto
Copy link
Member

@HeahDude I've tested your changes and it looks wrong for'format' => 'MM/yyyy' and'widget' => 'choice'. It display twochoice inputs (Month and Year) correctly, but on submit shows:

This value is not valid.

I think we need pass the right date fields toDateTimeToArrayTransformer (3rd param) when some field was ignored in format option (e.g. For'format' => 'MM/yyyy' should we passarray('year', 'month') only), otherwise it expects the three date fields always.

@HeahDude
Copy link
ContributorAuthor

HeahDude commentedDec 27, 2016
edited
Loading

@yceruto AFAIKformat option is meant to be used with thesingle_text widget since it is used to format the one field text only. This is also documented this wayhttp://symfony.com/doc/current/reference/forms/types/date.html#format.

EDIT
Ok but then we don't have the proper exception, I'm gonna move this throwing in theif/else below to keep both checks, thanks!

@yceruto
Copy link
Member

Ok but then we don't have the proper exception, I'm gonna move this throwing in the if/else below to keep both checks.

Do you plan to implement this one to all available widget here? It would be great to have custom/partial format forchoice widget too ;)

Theformat option (later$pattern) affects both widgets, and thechoice widget wasn't ready to accept custom/partial format. That's why this seems more as a new feature rather than a bug (IMHO).

@yceruto
Copy link
Member

If something helps you:yceruto@5e0d86c it is my quick proof to enable this feature on whole type. WDYT?

@HeahDudeHeahDudeforce-pushed thefix/datetime_type-format branch 2 times, most recently fromfbb55e7 toa8f8fb2CompareDecember 31, 2016 14:38
@HeahDude
Copy link
ContributorAuthor

I've updated the PR to fix the bug when using thesingle_text widget only, because IMHO it should only work as is, the only thing preventing it is a wrong configuration exception preventing to build the form.

If we want to handle this for other widgets that would imply a new way to configure the type so yeah I agree this is a new feature,@yceruto feel free to open a PR then :)

yceruto reacted with thumbs up emoji

@HeahDudeHeahDude changed the title[Form] Fixed DateType format option[Form] Fixed DateType format option for single text widgetDec 31, 2016
@xabbuh
Copy link
Member

xabbuh commentedDec 31, 2016
edited
Loading

@HeahDude I do not understand why the pattern should not contain all the subpatterns when thesingle_text widget is used. What is so different compared to other widgets?

@HeahDude
Copy link
ContributorAuthor

why the pattern should not contain all there subpatterns when the single_text widget is used

Because in this case thepattern get fromhere is simply used to format the date thanks to thetransformer.

For other widgets each part has to be extracted from it (refhttps://github.com/symfony/symfony/tree/2.7/src/Symfony/Component/Form/Extension/Core/Type/DateType.php#L90 andhttps://github.com/symfony/symfony/tree/2.7/src/Symfony/Component/Form/Extension/Core/Type/DateType.php#L277).

@HeahDudeHeahDudeforce-pushed thefix/datetime_type-format branch froma8f8fb2 to9e0d531CompareDecember 31, 2016 15:53
@xabbuh
Copy link
Member

@HeahDude But then the stricter test is only needed when thewidget option ischoice, right?

@HeahDude
Copy link
ContributorAuthor

@xabbuh No it looks like it's not, thetext widget also uses theDateTimeToArrayTransformer which fails to transform the submitted value on missing parts.

@nicolas-grekasnicolas-grekas added this to the2.7 milestoneJan 2, 2017
@xabbuh
Copy link
Member

@HeahDude Can you show me where this is done?


/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The "format" option should contain the letters "y", "M" or "d". Its current value is "wrong".
Copy link
Member

Choose a reason for hiding this comment

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

I would include the fact that this is testing the specific behaviour for thesingle_text widget (something liketestThrowExceptionIfFormatMissesYearMonthAndDayWithSingleTextWidget()).

Copy link
Member

Choose a reason for hiding this comment

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

done inad8f189

@xabbuh
Copy link
Member

👍

Status: Reviewed

@fabpot
Copy link
Member

Thank you@HeahDude.

@fabpotfabpot merged commit9e0d531 intosymfony:2.7Feb 4, 2017
fabpot added a commit that referenced this pull requestFeb 4, 2017
… (HeahDude)This PR was merged into the 2.7 branch.Discussion----------[Form] Fixed DateType format option for single text widget| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | ~| License       | MIT| Doc PR        | ~It's currently not possible to use a custom format with `DateType` when not using one of the three values day, month or year (i.e in my case "MM/yyyy").The formatter handles it, it looks like this option check is wrong, this PR fixes it.Commits-------9e0d531 [Form] Fixed DateType format option
@HeahDudeHeahDude deleted the fix/datetime_type-format branchFebruary 4, 2017 17:03
This was referencedFeb 6, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@xabbuhxabbuhxabbuh left review comments

Assignees

No one assigned

Projects

None yet

Milestone

2.7

Development

Successfully merging this pull request may close these issues.

6 participants

@HeahDude@xabbuh@yceruto@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp