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

Can I use this to validate if one of two fields is filled in? #85

Open
sert23 opened this issue Mar 28, 2018 · 1 comment
Open

Can I use this to validate if one of two fields is filled in? #85

sert23 opened this issue Mar 28, 2018 · 1 comment

Comments

@sert23
Copy link

sert23 commented Mar 28, 2018

Hi, great module!

I was wondering if I could use this to validate client-side if one of two fields from the form were used (only one of both is required).

So let's say you can either upload a file or a provide a link, so I want to validate that only one of these two is filled.

Thanks!

@droidzone
Copy link

I would like to do the same.
With parseley, you can validate if one of two fields is filled up with the following code:

`

$('#myform').parsley().on('form:validate', function (formInstance) {
if(formInstance.isValid({group: 'group1', force: true}) ||
formInstance.isValid({group: 'group2', force: true}) ||
formInstance.isValid({group: 'group3', force: true})) {
//do nothing
}
else {
$('#errorContainer').html('You must correctly fill at least one of these three groups!');
formInstance.validationResult = false;
}
});`

If my django form is:

@parsleyfy class RegisterPatientMetaForm(ModelForm): dob = forms.DateField( input_formats=['%d-%m-%y', '%Y-%m-%d'], widget=forms.DateInput(format='%d-%m-%y'), required=False ) class Meta: model = customer fields = [ 'name', 'ageyrs', 'agemnths', 'dob', 'gender', 'maritalstatus', 'mobile', 'alternate', 'email', 'address', 'city', 'occupation', 'bloodgroup' ] error_messages = { } unique_together = ["name", "mobile", "linkedclinic"]

How can I validate if one of dob or age in yrs is filled up?

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

No branches or pull requests

2 participants