-
Notifications
You must be signed in to change notification settings - Fork 43
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
Comments
Hello, thank you for your suggestion. Can you provide a use case for this? |
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. |
@AlexOstrovsky can you provide some code sample please? |
#[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? |
@Nek- any update on this? |
Hello @AlexOstrovsky , wouldn't it be more convenient to be able to specify many countries as valid? |
@Nek- thats also a possibility but I don't see any harm in making it repeatable |
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.... |
Because each repeated attribute has diffrent group. |
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? |
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. |
@Nek- so whats the conclusion? 😸 |
@AlexOstrovsky I guess both should be done. You can open a PR for sure. |
Would it be possible to make PhoneNumber attribute repeatable?
The text was updated successfully, but these errors were encountered: