jquery - Post to Python view after Javascript validation in Django -


i have template has form 2 input boxes. problem need ensure 1 of either box has filled value. is, 1 text box should empty. since django doesn't provide kind of or mechanism, checking through javascript in template:

function validatedata() {     if ($("#email").val() && $("#cellno").val()){         alert("please enter either e-mail address or cell number");     } else {         alert("form submitted successfully");         // redirect view_2     } } 

the issue want send data textbox view_2. how can send value of textbox , perform validation? without js validation have added url form action.

i'm not sure mean 'django doesn't provide kind of or mechanism'. if you're using django forms in view, can write clean method validates fields depend on each other.

class myform(forms.form):     email = forms.emailfield(required=false)     cell = forms.charfield(required=false, max_length=20)      def clean(self):         cleaned_data = super(myform, self).clean()         if cleaned_data.get('email') , cleaned_data.get('cell'):             raise forms.validationerror("please select either e-mail address or cell number, not both")         return cleaned_data 

Comments