def test_use_custom_control_is_used_in_checkboxes(): form = CheckboxesSampleForm() form.helper = FormHelper() form.helper.layout = Layout( "checkboxes", InlineCheckboxes("alphacheckboxes"), "numeric_multiple_checkboxes", ) # form.helper.use_custom_control take default value which is True assert parse_form(form) == parse_expected( "bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true.html" ) form.helper.use_custom_control = True assert parse_form(form) == parse_expected( "bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true.html" ) form.helper.use_custom_control = False assert parse_form(form) == parse_expected( "bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_false.html" ) form = CheckboxesSampleForm({}) form.helper = FormHelper() form.helper.layout = Layout( "checkboxes", InlineCheckboxes("alphacheckboxes"), "numeric_multiple_checkboxes", ) assert parse_form(form) == parse_expected( "bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true_failing.html" )
def __init__(self, *args, **kwargs): super(DomainFilter, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = "get" self.helper.form_class = "newitem" self.helper.form_show_labels = False # Layout the form for Bootstrap self.helper.layout = Layout( Row( Column( PrependedText("name", '<i class="fas fa-filter"></i>'), css_class="col-md-4 offset-md-2", ), Column( PrependedText("all_cat", '<i class="fas fa-filter"></i>'), css_class=" col-md-4", ), css_class="form-row", ), Accordion( AccordionGroup("Domain Status", InlineCheckboxes("domain_status")), AccordionGroup("Health Status", InlineCheckboxes("health_status")), ), ButtonHolder( Submit("submit_btn", "Filter", css_class="btn btn-primary col-md-2"), HTML(""" <a class="btn btn-outline-secondary col-md-2" role="button" href="{% url 'shepherd:domains' %}">Reset</a> """), ), )
def __init__(self, user=None, *args, **kwargs): super(MissioneForm, self).__init__(*args, **kwargs) if user: self.fields['automobile'].queryset = Automobile.objects.filter( user=user) self.helper = FormHelper() self.helper.form_method = 'post' # self.helper.form_class = 'form-horizontal' # self.helper.form_action = 'missione' try: _ = kwargs['instance'] self.helper.add_input(Submit('submit', 'Aggiorna')) except KeyError: self.helper.add_input(Submit('submit', 'Crea')) self.helper.layout = Layout( Row(Div('citta_destinazione', css_class="col-6"), Div('stato_destinazione', css_class="col-6")), Row(Div('inizio', css_class="col-3"), Div('inizio_ora', css_class="col-3"), Div('fine', css_class="col-3"), Div('fine_ora', css_class="col-3")), Row(Div('fondo', css_class="col-4"), Div('struttura_fondi', css_class="col-4"), Div('tipo', css_class="col-4")), Row(Div('motivazione', css_class="col-12")), Row(Div(InlineCheckboxes('mezzi_previsti'), css_class="col-6"), Div('automobile', css_class="col-6"), Div('automobile_altrui', css_class="col-6")), Row( Div(InlineCheckboxes('motivazione_automobile'), css_class="col-12")), )
def __init__(self, *args, **kwargs): super(SearchForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = "GET" self.helper.layout = Layout( Field("q"), InlineCheckboxes("obj_types"), InlineCheckboxes("include"), ButtonHolder(Submit("submit", "Search")), )
def test_use_custom_control_is_used(): form = CheckboxesSampleForm() form.helper = FormHelper() form.helper.layout = Layout("checkboxes", InlineCheckboxes("alphacheckboxes"), "numeric_multiple_checkboxes") # form.helper.use_custom_control take default value which is True response = render(request=None, template_name="crispy_render_template.html", context={"form": form}) assert response.content.count(b"custom-control-inline") == 3 assert response.content.count(b"custom-checkbox") == 9 form.helper.use_custom_control = True response = render(request=None, template_name="crispy_render_template.html", context={"form": form}) assert response.content.count(b"custom-control-inline") == 3 assert response.content.count(b"custom-checkbox") == 9 form.helper.use_custom_control = False response = render(request=None, template_name="crispy_render_template.html", context={"form": form}) assert response.content.count(b"custom-control-inline") == 0 assert response.content.count(b"form-check-inline") == 3 assert response.content.count(b"form-check") > 0 assert response.content.count(b"custom-checkbox") == 0
def __init__(self, *args, **kwargs): super(AdminEventForm, self).__init__(*args, **kwargs) self.fields['categories'].required = False self.helper.layout.append(Layout( InlineCheckboxes('categories') ))
def test_use_custom_control_is_used(): form = CheckboxesSampleForm() form.helper = FormHelper() form.helper.layout = Layout('checkboxes', InlineCheckboxes('alphacheckboxes'), 'numeric_multiple_checkboxes') # form.helper.use_custom_control take default value which is True response = render(request=None, template_name='crispy_render_template.html', context={'form': form}) assert response.content.count(b'custom-control-inline') == 3 assert response.content.count(b'custom-checkbox') == 9 form.helper.use_custom_control = True response = render(request=None, template_name='crispy_render_template.html', context={'form': form}) assert response.content.count(b'custom-control-inline') == 3 assert response.content.count(b'custom-checkbox') == 9 form.helper.use_custom_control = False response = render(request=None, template_name='crispy_render_template.html', context={'form': form}) assert response.content.count(b'custom-control-inline') == 0 assert response.content.count(b'form-check-inline') == 3 assert response.content.count(b'form-check') > 0 assert response.content.count(b'custom-checkbox') == 0
def test_keepcontext_context_manager(settings): # Test case for issue #180 # Apparently it only manifest when using render_to_response this exact way form = CheckboxesSampleForm() form.helper = FormHelper() # We use here InlineCheckboxes as it updates context in an unsafe way form.helper.layout = Layout( 'checkboxes', InlineCheckboxes('alphacheckboxes'), 'numeric_multiple_checkboxes' ) context = {'form': form} response = render( request=None, template_name='crispy_render_template.html', context=context ) if settings.CRISPY_TEMPLATE_PACK == 'bootstrap': assert response.content.count(b'checkbox inline') == 3 elif settings.CRISPY_TEMPLATE_PACK == 'bootstrap3': assert response.content.count(b'checkbox-inline') == 3 elif settings.CRISPY_TEMPLATE_PACK == 'bootstrap4': assert response.content.count(b'custom-control-inline') == 3 assert response.content.count(b'custom-checkbox') > 0
def __init__(self, *args, **kwargs): super(WorkupForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.layout = Layout( Row(HTML('<h3>Clinical Team</h3>'), Div('attending', css_class='col-sm-6'), Div('other_volunteer', css_class='col-sm-6'), Div('clinic_day', css_class='col-sm-12')), Row( HTML('<h3>History</h3>'), Div('chief_complaint', css_class='col-sm-6'), Div('diagnosis', css_class='col-sm-6'), Div(InlineCheckboxes('diagnosis_categories'), css_class='col-xs-12'), Div('HPI', css_class='col-xs-12'), Div('PMH_PSH', css_class='col-xs-12'), Div('fam_hx', css_class='col-md-6'), Div('soc_hx', css_class='col-md-6'), Div('meds', css_class='col-md-6'), Div('allergies', css_class='col-md-6'), Div('ros', css_class='col-xs-12')), Row( HTML('<h3>Physical Exam</h3>'), HTML('<h4>Vital Signs</h4>'), Div(AppendedText('bp_sys', 'mmHg'), css_class='col-md-3 col-sm-3 col-xs-6'), Div(AppendedText('bp_dia', 'mmHg'), css_class='col-md-3 col-sm-3 col-xs-6'), Div(AppendedText('hr', 'bpm'), css_class='col-md-3 col-sm-3 col-xs-6'), Div(AppendedText('rr', '/min'), css_class='col-md-3 col-sm-3 col-xs-6')), Row( Div(AppendedRadios('t', 'temperature_units'), css_class='col-md-3 col-sm-3 col-xs-6'), Div(AppendedRadios('weight', 'weight_units'), css_class='col-md-3 col-sm-4 col-xs-6'), Div(AppendedRadios('height', 'height_units'), css_class='col-md-3 col-sm-4 col-xs-6'), Div('pe', css_class='col-xs-12')), Row( HTML('<h3>Assessment, Plan, & Orders</h3>'), Div('A_and_P', css_class='col-xs-12'), Div('rx', css_class='col-md-4'), Div('labs_ordered_internal', css_class='col-md-4'), Div('labs_ordered_quest', css_class='col-md-4'), Div( HTML('<h4>Medication Voucher</h4>'), 'got_voucher', PrependedText('voucher_amount', '$'), PrependedText('patient_pays', '$'), css_class='col-xs-6', ), Div(HTML('<h4>Imaging Voucher</h4>'), 'got_imaging_voucher', PrependedText('imaging_voucher_amount', '$'), PrependedText('patient_pays_imaging', '$'), css_class='col-xs-6')), Submit('submit', 'Save', css_class='btn btn-success'))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = "get" self.helper.form_class = "newitem" self.helper.form_show_labels = False # Layout the form for Bootstrap self.helper.layout = Layout( Row( Column( PrependedText("ip_address", '<i class="fas fa-filter"></i>'), css_class="col-md-6", ), Column( PrependedText("name", '<i class="fas fa-filter"></i>'), css_class=" col-md-6", ), css_class="form-row", ), Accordion( AccordionGroup("Server Status", InlineCheckboxes("server_status")), ), ButtonHolder( HTML(""" <a class="btn btn-info col-md-2" role="button" href="{% url 'shepherd:server_create' %}">Create</a> """), Submit("submit_btn", "Filter", css_class="btn btn-primary col-md-2"), HTML(""" <a class="btn btn-outline-secondary col-md-2" role="button" href="{% url 'shepherd:servers' %}">Reset</a> """), ), )
def test_inline_checkbox(self): form = CheckboxMultiple() form.helper = FormHelper() form.helper.form_tag = False form.helper.layout = Layout(InlineCheckboxes("checkbox")) html = render_crispy_form(form) expected_html = """ <div id="div_id_checkbox" class="mb-3"> <label for="" class="block text-gray-700 text-sm font-bold mb-2 requiredField"> Checkbox<span class="asteriskField">*</span> </label> <div id="div_id_checkbox" class="flex flex-row"> <div class="mr-3"> <label class="block text-gray-700" for="id_checkbox_1"> <input type="checkbox" class="" name="checkbox" id="id_checkbox_1" value="blue" /> Blue </label> </div> <div class="mr-3"> <label class="block text-gray-700" for="id_checkbox_2"> <input type="checkbox" class="" name="checkbox" id="id_checkbox_2" value="green" /> Green </label> </div> </div> </div> """ self.assertHTMLEqual(html, expected_html)
class PersonForm(forms.ModelForm): helper = FormHelper() helper.form_tag = False helper.html5_required = True helper.layout = Layout( Div(Div('is_active', 'first_name', 'last_name', 'email', 'telephone', css_class="col-md-6", style="margin-top: 10px;"), Div('based_at', InlineCheckboxes('groups'), HTML(""" <a href="{% url 'password_change' %}" class="btn btn-default">Change User Password</a> NB: This requires the user's existing password to be used. """), css_class="col-md-6", style="margin-top: 10px;"), css_class="row")) def __init__(self, data=None, *args, **kwargs): super(PersonForm, self).__init__(data=data, *args, **kwargs) self.render_required_fields = True class Meta: model = Person fields = ('is_active', 'first_name', 'last_name', 'telephone', 'email', 'based_at', 'groups')
class NewPackageForm(forms.Form): """ Add new package to package list """ platform_choices = () products_choices = () package_name = forms.CharField( label='Package Name', help_text= 'Package id as-in translation platform. Use hyphen (-) to separate words.', required=True, ) upstream_url = forms.URLField( label='Upstream URL', help_text='Source repository location (Bitbucket, GitHub, Pagure etc).', required=True) transplatform_slug = forms.ChoiceField( label='Translation Platform', choices=platform_choices, help_text='Translation statistics will be fetched from this server.') release_streams = TextArrayField( label='Products', widget=forms.CheckboxSelectMultiple, choices=products_choices, help_text="Translation progress for selected products will be tracked." ) def __init__(self, *args, **kwargs): self.platform_choices = kwargs.pop('platform_choices') self.products_choices = kwargs.pop('products_choices') super(NewPackageForm, self).__init__(*args, **kwargs) self.fields['transplatform_slug'].choices = self.platform_choices self.fields['release_streams'].choices = self.products_choices super(NewPackageForm, self).full_clean() helper = FormHelper() helper.form_method = 'POST' helper.form_action = '/packages/new' helper.form_class = 'dynamic-form' helper.error_text_inline = True helper.form_show_errors = True helper.layout = Layout( Div( Field('package_name', css_class='form-control', onkeyup="showPackageSlug()"), Field('upstream_url', css_class='form-control'), Field('transplatform_slug', css_class='selectpicker'), InlineCheckboxes('release_streams'), HTML("<hr/>"), HTML( "<h5 class='text-info'>Servers configured here may be contacted at intervals.</h5>" ), FormActions(Submit('addPackage', 'Add Package'), Reset('reset', 'Reset', css_class='btn-danger')))) def is_valid(self): return False if len(self.errors) >= 1 else True
def __init__(self, *args, **kwargs): super(AppsGrantPermission, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.layout = Layout('updateUser',InlineCheckboxes('perm')) self.helper[0].wrap(Column, css_class='col-md-3') self.helper[1].wrap(Column, css_class='col-md-4') self.helper[0:2].wrap_together(Row, css_class='form_row')
def __init__(self, *args, **kwargs): super(AuditionForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.form_tag = False self.helper.layout = Layout( 'group', Field('location', css_class='autocomplete'), 'email', InlineCheckboxes('voice_parts'), 'description') self.helper.add_input(Submit('submit', 'Submit'))
def __init__(self, *args, **kwargs): """ Override to change the display for a Model(Multi)ChoiceField, using the field name and the 'label_from_instance' attribute. :param args: :param kwargs: """ super().__init__(*args, **kwargs) self.fields[ 'publisher'].label_from_instance = lambda obj: "%s" % obj.name self.fields['isbn'].label = 'ISBN' self.fields['format'].empty_label = None self.helper = FormHelper() self.helper.form_id = 'id-add-book-form' self.helper.form_method = 'post' self.helper.form_action = 'create-book' # modify the layout for the form self.helper.layout = Layout( Field('title'), # use this layout to add a '+' button inline with the select widget (for authors); used to add a new author. # This opens a new form for adding an author, and the success (and cancel) route is back to this 'add book' form. # If the 'add author' for is to be used from a different context, e.g. an 'Add Author' button on the Authors List page, # then changes are necessary, e.g. to add a '?next' query string to the route url, etc. # See this SO for how to make the select and link appear inline: http://stackoverflow.com/a/31226655/2152249 Div(Field('authors', style='display: inline-block;'), HTML( """<span class="input-group-btn"><a href="{% url 'create-author' %}" class="btn btn-link"><span class="glyphicon glyphicon-plus"></span></a></span>""" ), css_class="input-group"), # use this to group the publisher and pub_date in a fieldset. # use the same technique as above to add a '+' button (for adding a new Publisher instance). Fieldset( 'Publishing', Div(Field('publisher', style='display: inline-block;'), HTML( """<span class="input-group-btn"><a href="{% url 'create-publisher' %}" class="btn btn-link"><span class="glyphicon glyphicon-plus"></span></a></span>""" ), css_class="input-group"), # 'publisher', 'pub_date'), # Use this fieldset to group 'book information' Fieldset( 'Book Info', # name of the fieldset # the 'isbn' field is supposed to be numeric (not validated) and it is prefixed with 'isbn' string PrependedText('isbn', 'ISBN'), # use inline radio button instead of the default select widget (single selection) InlineRadios('format'), # use inline checkboxes instead of the default select widget (multiple selection) InlineCheckboxes('category'), 'book_cover'), # group the buttons FormActions( Submit('save', 'Save'), # use a link for Cancel HTML( """<a href="{% url 'books' %}" class="btn btn-secondary">Cancel</a>""" )))
class IndHelper(FormHelper): form_class = 'form-horizontal' label_class = 'col-lg-2' field_class = 'col-lg-8' form_method = 'GET' layout = Layout( Div(Div(Div( Div('individuo', 'trabajo', 'jardin', InlineCheckboxes('prestador'), InlineCheckboxes('transporte')), Div( Submit('submit', 'Aplicar Filtros', css_class='btn btn-primary'), css_class='col-lg-offset-3 col-lg-9', )), css_class="card"), id="filters", css_class="collapse"))
def __init__(self, *args, submit_title="TITLE", **kwargs): super(MotForm, self).__init__(*args, **kwargs) correct_arraylist(self) # Crérer le helper (pour le rendering) self.helper = FormHelper(self) self.helper.form_tag = False self.helper.render_required_fields = True self.helper.form_class = 'form-vertical' self.helper.form_id = 'id-mot-form' self.helper.layout = Layout( Div(Div(HTML("<h3>Masculins</h3>"), css_class=("card-header")), Div(Row( Div('masculin_singulier', css_class="col-sm-3"), Div('masculin_pluriel', css_class="col-sm-3"), Div('validation', css_class="col-sm-2"), Div('terminaison', css_class="col-sm-2"), UneditableField('source', readonly=True), ), Row( InlineCheckboxes('problème_signalé', css_class="col-sm-4"), Field('visible', css_class="col-sm-4"), ), Row(Div('masculin_sinuglier_autres', css_class="col-sm-6"), Div('masculin_pluriel_autres', css_class="col-sm-6"), css_class='row'), fréquenceLayout, dictionnairesLayout, notesLayout, css_class="card-body"), css_class="card"), # Div( # Div(HTML("<h3>Caracteristiques</h3>"), css_class=("card-header")), # Div( # Div( # # HTML('source: {{ form.instance.source }}'), # css_class='row' # ), # Div( # Div('commentaire_externe', css_class="col-sm-6"), # Div('liens', css_class="col-sm-6"), # css_class='row' # ), # Div( # Div(Field('commentaires_internes_text', readonly=True), css_class="col-sm-6"), # Div('new_commentaire_interne', css_class="col-sm-6"), # css_class='row' # ), # css_class="card-body" # ), # css_class="card" # ), )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_class = 'form-inline' self.helper.field_template = 'bootstrap3/layout/inline_field_with_label.html' self.helper.form_method = 'get' self.helper.layout = Layout( 'structure', InlineCheckboxes('state'), )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.fields['reg_data'].label = False self.fields['data_classi'].label = False self.fields['recs_purged'].label = False self.fields['data_process_outside'].label = False self.fields['data_stored_outside'].label = False self.fields['data_rcvd_outside'].label = False self.fields['data_accss_outside'].label = False self.helper.layout = Layout( InlineCheckboxes('reg_data'), InlineCheckboxes('data_classi'), InlineRadios('recs_purged'), InlineRadios('data_process_outside'), InlineRadios('data_stored_outside'), InlineRadios('data_rcvd_outside'), InlineRadios('data_accss_outside'), )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = "get" self.helper.form_class = "newitem" self.helper.form_show_labels = False # Layout the form for Bootstrap self.helper.layout = Layout( Div( Row( Column( PrependedText("title", '<i class="fas fa-filter"></i>'), css_class="form-group col-md-6 offset-md-3 mb-0", ), css_class="form-row", ), Row( Column( InlineCheckboxes("severity"), css_class="form-group col-md-12 m-1", ), css_class="form-row", ), Row( Column( InlineCheckboxes("finding_type"), css_class="form-group col-md-12 m-1", ), css_class="form-row", ), ButtonHolder( HTML(""" <a class="btn btn-info col-md-2" role="button" href="{% url 'reporting:finding_create' %}">Create</a> """), Submit("submit_btn", "Filter", css_class="col-md-2"), HTML(""" <a class="btn btn-outline-secondary col-md-2" role="button" href="{% url 'reporting:findings' %}">Reset</a> """), ), css_class="justify-content-center", ), )
class StatusFilterForm(CrispyFilterMixin, forms.Form): status = forms.MultipleChoiceField( choices=models.Leistung.STATUS, widget=forms.CheckboxSelectMultiple, label="Bearbeitungsstatus", required=False, initial=[ models.Leistung.STATUS[0][0], models.Leistung.STATUS[2][0], ], ) __layout = Layout(InlineCheckboxes('status'), )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['buns'].queryset = (Ingredients.objects.filter(cat='Bun')) self.fields['burger'].queryset = (Ingredients.objects.filter( cat='Burger')) self.fields['sauce'].queryset = (Ingredients.objects.filter( cat='Sauce')) self.fields['salads'].queryset = (Ingredients.objects.filter( cat='Salad')) self.fields['cheese'].queryset = (Ingredients.objects.filter( cat='Cheese')) self.fields['extras'].queryset = (Ingredients.objects.filter( cat='Extras')) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.layout = Layout( Row(Column('custom_name'), ), InlineCheckboxes('buns'), InlineCheckboxes('burger'), InlineCheckboxes('sauce'), InlineCheckboxes('salads'), InlineCheckboxes('cheese'), InlineCheckboxes('extras'), FormActions( Submit('create_burger', 'Create Burger', css_class='btn btn-secondary')))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = "get" self.helper.form_class = "newitem" self.helper.form_show_labels = True # Layout the form for Bootstrap self.helper.layout = Layout( Row( Column( PrependedText("name", '<i class="fas fa-filter"></i>'), css_class="col-md-6", ), Column( PrependedText("categorization", '<i class="fas fa-filter"></i>'), css_class="col-md-6", ), css_class="form-row", ), Accordion( AccordionGroup("Domain Status", InlineCheckboxes("domain_status"), SwitchToggle("exclude_expired")), AccordionGroup("Health Status", InlineCheckboxes("health_status")), ), ButtonHolder( HTML(""" <a class="btn btn-info col-md-2" role="button" href="{% url 'shepherd:domain_create' %}">Create</a> """), Submit("submit_btn", "Filter", css_class="btn btn-primary col-md-2"), HTML(""" <a class="btn btn-outline-secondary col-md-2" role="button" href="{% url 'shepherd:domains' %}">Reset</a> """), ), )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'application' self.helper.form_method = 'post' self.helper.layout = Layout('name', 'surname', 'city', 'state', 'phoneNumber', 'emailAddress', 'university', InlineCheckboxes('languages'), 'other_files_field', Field('CV_file', readonly=True), Field('skills', type='hidden')) self.helper.add_input(Submit('submit', 'Zatwierdź'))
class ComicForm(BaseCoreModelForm): genres = forms.ModelMultipleChoiceField( queryset=models.Genre.objects, widget=forms.CheckboxSelectMultiple, ) helper = FormHelper() helper.layout = Layout(InlineCheckboxes('genres')) class Meta: model = models.Comic fields = '__all__'
class AncHelper(FormHelper): form_class = 'form-horizontal' label_class = 'col-lg-2' field_class = 'col-lg-8' form_method = 'GET' layout = Layout( Div( Div( Div( #Error prestador Div('id', InlineCheckboxes('prestador'), InlineCheckboxes('tipo'), 'sector_auto', 'sector_caminando', 'sector_bus', 'hora_inicio', 'hora_fin'), Div( Submit('submit', 'Aplicar Filtros', css_class='btn btn-primary'), css_class='col-lg-offset-3 col-lg-9', )), css_class="card"), id="filters", css_class="collapse"))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) helper = self.helper = FormHelper() loadData() self.fields['chronics'] = forms.MultipleChoiceField( choices=chronicsData, widget=forms.SelectMultiple(attrs={ 'class': 'form-control', 'id': 'chronics' })) self.fields['allergies'] = forms.MultipleChoiceField( choices=allergiesData, widget=forms.SelectMultiple(attrs={ 'class': 'form-control', 'id': 'allergies' })) helper.form_method = 'post' # get or post helper.form_action = '' helper.form_id = 'patientAllr' helper.form_show_labels = False self.fields['chronics'].label = False self.fields['allergies'].label = False self.fields['chronics'].required = False self.fields['allergies'].required = False self.helper.layout = Layout( Div( Row(Column(HTML("<h5>Chronics</h5>"), InlineCheckboxes('chronics'), css_class='form-group col-md-6'), Column(HTML("<h5>Allergic Drugs</h5>"), InlineCheckboxes('allergies'), css_class='form-group col-md-6'), css_class='register-form'), Submit('regPatient', 'Add Chronic/Allergies', css_class='btn-primary', css_id='paregbtn'), ))
def __init__(self, *args, **kwargs): super(AnswerForm, self).__init__(*args, **kwargs) question = self.instance.question self.choices = question.choice_set.all().order_by('sort_value') choice_tup = ((x.id, x) for x in self.choices) self.helper = FormHelper() self.helper.error_text_inline = False self.helper.help_text_inline = True self.helper.form_tag = False #custom layout if question.type == 0: self.fields['answer'] = forms.ChoiceField( choices=(choice_tup), widget=forms.RadioSelect(), label=question, required=False, help_text=question.help) field = InlineRadios('answer', wrapper_class='radio-form', required=False) elif question.type == 1: self.fields['answer'] = forms.MultipleChoiceField( choices=(choice_tup), label=question, required=False) field = InlineCheckboxes('answer', choices=choice_tup, wrapper_class='radio-form') elif question.type == 2: self.fields['answer'] = forms.CharField(label=question, required=False) field = Field('answer') isHide = question.parent is not None self.helper.layout = Layout( Div( field, css_class="questionDiv", css_id="question-" + str(question.pk), hidden=isHide, ), Div(Field('user'), hidden=True)) if (question.hascomment == 1): self.fields['comment'] = forms.CharField( label="", required=False, widget=forms.Textarea(attrs={ 'cols': 1, 'rows': 2 })) self.helper.layout[0].append( Field('comment', placeholder="comment", css_class='question-comment'))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['year'].initial = settings.NOW().year self.helper = FormHelper() self.helper.form_class = 'form-inline' self.helper.field_template = 'bootstrap3/layout/inline_field_with_label.html' self.helper.form_method = 'get' self.helper.layout = Layout( 'structure', 'year', 'month', 'org_type', InlineCheckboxes('state'), )