Skip to content
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

Make constraint repeatable #146

Closed
AlexOstrovsky opened this issue Apr 24, 2023 · 14 comments
Closed

Make constraint repeatable #146

AlexOstrovsky opened this issue Apr 24, 2023 · 14 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@AlexOstrovsky
Copy link

AlexOstrovsky commented Apr 24, 2023

Would it be possible to make PhoneNumber attribute repeatable?

#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
class PhoneNumber extends Constraint
{
}
@Nek-
Copy link
Collaborator

Nek- commented Jul 4, 2023

Hello, thank you for your suggestion. Can you provide a use case for this?

@maxhelias maxhelias added the enhancement New feature or request label Jul 4, 2023
@AlexOstrovsky
Copy link
Author

AlexOstrovsky commented Jul 4, 2023

Hi @Nek- yes my use case is I have one class where I have $phoneNumber for multiple countries and I want to validate phoneNumber per country based on groups which represent countryIso. Currently I am extending the attribute from this bundle and just adding IS_REPEATABLE to it.

@maxhelias maxhelias added the good first issue Good for newcomers label Jul 4, 2023
@Nek-
Copy link
Collaborator

Nek- commented Jul 4, 2023

@AlexOstrovsky can you provide some code sample please?

@AlexOstrovsky
Copy link
Author

AlexOstrovsky commented Jul 4, 2023

@Nek-

#[PhoneNumber(format: PhoneNumberFormat::E164, type: [\Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::MOBILE], defaultRegion: CountryIso::LATVIA->value, message: 'GSM.INVALID', groups: [CountryIso::LATVIA->value])]
#[PhoneNumber(format: PhoneNumberFormat::E164, type: [\Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::MOBILE], defaultRegion: CountryIso::ESTONIA->value, message: 'GSM.INVALID', groups: [CountryIso::ESTONIA->value])]
#[PhoneNumber(format: PhoneNumberFormat::E164, type: [\Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber::MOBILE], defaultRegion: CountryIso::DENMARK->value, message: 'GSM.INVALID', groups: [CountryIso::DENMARK->value])] 
public ?PhoneNumberObject $gsm = null;

did you mean this or something else?

@AlexOstrovsky
Copy link
Author

@Nek- any update on this?

@maxhelias maxhelias added the help wanted Extra attention is needed label Nov 3, 2023
@Nek-
Copy link
Collaborator

Nek- commented Nov 6, 2023

Hello @AlexOstrovsky , wouldn't it be more convenient to be able to specify many countries as valid?

@AlexOstrovsky
Copy link
Author

@Nek- thats also a possibility but I don't see any harm in making it repeatable

@Nek-
Copy link
Collaborator

Nek- commented Nov 7, 2023

TBH didn't test it and I do not understand how there's not 2 failing no matter what. If the validator is called 3 times, then it will necessarily fail 2 times....

@AlexOstrovsky
Copy link
Author

Because each repeated attribute has diffrent group.

@Nek-
Copy link
Collaborator

Nek- commented Nov 7, 2023

Oh ok, from what I understand, you are using groups as a workaround because there's no possibility to specify many countries in the constraints, or am I missing something?

@AlexOstrovsky
Copy link
Author

My use case is like this: I have one API endpoint lets call it /api/formSubmit. This API endpoint is universal for all countries. But not all countries have all fields on frontend and phone number validation is diffreent per country. So I am using the groups (which represent country) to define what constraints should be validated in which country.

@AlexOstrovsky
Copy link
Author

@Nek- so whats the conclusion? 😸

@Nek-
Copy link
Collaborator

Nek- commented Nov 16, 2023

@AlexOstrovsky I guess both should be done. You can open a PR for sure.

@AlexOstrovsky
Copy link
Author

@Nek- I opened the PR: #167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants