in Education by
I have a large django form. It has a lot of data that depends on a field being selected. Eg: Do you have a car? YES/NO dropdown box. If yes, I want to show the additional fields make/model/year/cc etc etc If no, I want to keep them hidden. What is the best way to this? A simple show/hide div using jquery or is there something better that I should be doing? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Yes, you should use a simple show/hide with JQuery on the client side. Then on the server side, you would need conditional validation in your form's clean method, if you also want to make some fields required only if something else is selected. For example: class MyForm(Form): ... def clean(self): cleaned_data = self.cleaned_data has_car_required_fields = ['foo', 'bar', 'baz'] if cleaned_data.has_key('has_car') and cleaned_data['has_car']: for field_name in has_car_required_fields: if not cleaned_data.has_key(field_name) or not cleaned_data[field_name]: self._errors[field_name] = ErrorList([_(u'This field is required')]) return cleaned_data

Related questions

0 votes
    I'm using Semantic-UI-React in my React/Rails project and trying to use a Form.Select drop down ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I'm using Semantic-UI-React in my React/Rails project and trying to use a Form.Select drop down ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Is it possible to assign the field type dynamically - Django Form? field_type = 'CharField' field = forms. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Is it possible to assign the field type dynamically - Django Form? field_type = 'CharField' field = forms. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    The concentration of a reactant changes form 0.03M to 0.02M in 25min. Calculate the average rate of reaction ... minutes and seconds. Select the correct answer from above options...
asked Jan 4, 2022 in Education by JackTerrance
0 votes
    exchange in which no new substance is formed and the changes only in the form of the substance Select the correct answer from above options...
asked Dec 6, 2021 in Education by JackTerrance
0 votes
    exchange in which no new substance is formed and the changes only in the form of the substance Select the correct answer from above options...
asked Dec 5, 2021 in Education by JackTerrance
0 votes
    exchange in which no new substance is formed and the changes only in the form of the substance Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    Which of the following attribute triggers events when a form changes?...
asked Apr 10, 2021 in Education by JackTerrance
0 votes
    EDIT : This issue also concerns Material Ui's Data table. I tried using the same example as given by the documentation ... of these script tags are needed for the old legacy app)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
     On the Origin of Species, by Means of Natural Selection' was written by (a) Hugo de Vries ... Science,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 8, 2021 in Education by JackTerrance
0 votes
    If access paths are available on all the conditions of a disjunctive selection, each index is scanned ... Operation in division Query Processing Techniques of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    My goal is to host Django app on CentOs 7 with python3.10 I've manage to download and configure ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Django is based on which architecture? 1. MTV 2. MVC 3. MVTT 4. MVP...
asked Jul 4, 2021 in Technology by JackTerrance
0 votes
    I have a @Stateless-Bean which performs some Database operations in a single method public void doOperation() ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
...