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] Add the EnumType#43095

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:5.4fromderrabus:feature/form-enum-type
Sep 21, 2021
Merged

Conversation

@derrabus
Copy link
Member

@derrabusderrabus commentedSep 19, 2021
edited
Loading

QA
Branch?5.4
Bug fix?no
New feature?yes
Deprecations?no
TicketsN/A
LicenseMIT
Doc PRTODO

This PR adds a newEnumType that enables the form component to configure aChoiceType for a native PHP enum.

Example:

enum Suit:string{case Hearts ='H';case Diamonds ='D';case Clubs ='C';case Spades ='S';}enum Rank:string{case Ace ='A';case King ='K';case Queen ='Q';case Jack ='J';case Ten ='X';case Nine ='9';case Eight ='8';case Seven ='7';case Six ='6';case Five ='5';case Four ='4';case Three ='3';case Two ='2';}finalclass Card{public ?Suit$suit =null;public ?Rank$rank =null;}
$form =$this    ->createFormBuilder(null, ['data_class' => Card::class])    ->add('suit', EnumType::class, ['class' => Suit::class,'required' =>false,'expanded' =>true])    ->add('rank', EnumType::class, ['class' => Rank::class,'required' =>false])    ->add('submit', SubmitType::class)    ->getForm()    ->handleRequest($request);

Bildschirmfoto 2021-09-19 um 18 06 39

GromNaN, OskarStark, alexandre-daubois, W0rma, ro0NL, AsheK, alamirault, zmitic, and sansxd reacted with thumbs up emojialexandre-daubois, yceruto, and W0rma reacted with rocket emoji
@derrabusderrabusforce-pushed thefeature/form-enum-type branch 2 times, most recently frome14f102 to51ef328CompareSeptember 19, 2021 16:27
@stof
Copy link
Member

please also add a test covering the case of enums backed by integers rather than strings.

@derrabusderrabusforce-pushed thefeature/form-enum-type branch 2 times, most recently from268a8f4 to55b0debCompareSeptember 19, 2021 16:51
@derrabus
Copy link
MemberAuthor

please also add a test covering the case of enums backed by integers rather than strings.

Good idea, done!

@derrabusderrabusforce-pushed thefeature/form-enum-type branch 3 times, most recently from7fd97b3 to0f08e0aCompareSeptember 19, 2021 17:12
@nicolas-grekasnicolas-grekas added this to the5.4 milestoneSep 19, 2021
Copy link
Member

@ycerutoyceruto left a comment

Choose a reason for hiding this comment

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

👍 just a minor inaccuracy about whatchoice_value callback should return (it's the string "value" of each choice)

derrabus reacted with heart emoji
Copy link
Contributor

@TobionTobion left a comment

Choose a reason for hiding this comment

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

Very clean. Just missing a changelog entry.

derrabus reacted with thumbs up emoji
Signed-off-by: Alexander M. Turek <me@derrabus.de>
@fabpot
Copy link
Member

Thank you@derrabus.

@rccc
Copy link

rccc commentedMar 27, 2025
edited
Loading

Hello,

We cannot do this:

enum MoleculeFields: string { case Molecule Name = 'Molecule Name'; }

but we can do this

enum MoleculeFields: string { case Molecule_Name = 'Molecule Name'; }
Or even

enum MoleculeFields: string { case MoleculeName = 'Molecule Name'; }

But "molecule_name" or "v" will be display in the select field.

How wan we display "Molecue Name" while havinf "molecule_name" in the field value attribute ?

Eric

@xabbuh
Copy link
Member

For support, please refer to one of thesupport channels. Thank you for understanding.

derrabus reacted with thumbs up emoji

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

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

@ycerutoycerutoyceruto approved these changes

@xabbuhxabbuhAwaiting requested review from xabbuhxabbuh is a code owner

+1 more reviewer

@TobionTobionTobion approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

9 participants

@derrabus@stof@fabpot@rccc@xabbuh@Tobion@yceruto@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp