def test_form_show_labels(): form = SampleForm() form.helper = FormHelper() form.helper.layout = Layout( "password1", FieldWithButtons("password2", StrictButton("Confirm")), PrependedText("first_name", "Mr."), AppendedText("last_name", "@"), PrependedAppendedText("datetime_field", "on", "secs"), ) form.helper.form_show_labels = False html = render_crispy_form(form) assert html.count("<label") == 0
def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.layout = Layout( FieldWithButtons( 'session_id', StrictButton('Connect', css_class="btn btn-light border border-dark", type='Submit'))) super(SessionConnectForm, self).__init__(*args, **kwargs) self.fields['session_id'].required = True self.fields['session_id'].validators = [validate_session_id] self.fields['session_id'].widget.attrs.update( {'placeholder': 'Enter ID'}) self.fields['session_id'].label = ""
def __init__(self, *args, **kwargs): super(SubscriberSendSMSForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'id-SubscriberSendSMSForm' self.helper.form_method = 'post' params = {'imsi': kwargs.get('initial').get('imsi')} self.helper.form_action = urlresolvers.reverse('subscriber-send-sms', kwargs=params) self.helper.form_class = 'col-xs-12 col-md-8 col-lg-6' self.helper.layout = Layout( 'imsi', FieldWithButtons( 'message', StrictButton('Send', css_class='btn-default', type='submit')))
def __init__(self, *args, **kwargs): super(BookCompanyForm, self).__init__(*args, **kwargs) packages = Package.objects.filter( Q(is_full=False) or Q(companies=self.instance) ) self.fields["package"].queryset = packages self.helper = FormHelper() self.helper.layout = Layout( FieldWithButtons( "package", StrictButton(_("Save"), type="submit", css_class="btn-success"), ) )
def __init__(self, sender, *args, **kwargs): self.helper = FormHelper() self.helper.form_id = 'id-SearchForm' self.helper.form_method = 'get' if 'blocking' is sender: self.helper.form_action = '/dashboard/user/management/blocking' else: self.helper.form_action = '/dashboard/user/management/delete' # self.helper.form_class = 'form-vertical' search_button = StrictButton('Find', css_class='btn-default', type='submit') self.helper.layout = Layout(FieldWithButtons('query', search_button)) super(UserSearchForm, self).__init__(*args, **kwargs)
def __init__(self, *args, person, **kwargs): super().__init__(*args, **kwargs) self.person = person fields = [ Row( HalfCol( FieldWithButtons("code", Submit("submit", "Valider mon numéro")) ) ) ] self.helper = FormHelper() self.helper.form_method = "POST" self.helper.layout = Layout(*fields)
def __init__(self, *args, **kwargs): super(ClientForm, self).__init__(*args, **kwargs) self.helper.form_action = reverse("crm.views.client") self.helper.layout = Layout( Div(Column(AppendedText( "organisation", "<a href='%s' target='_blank'><span class='glyphicon glyphicon-plus'></span></a>" % reverse("crm.views.clientOrganisation")), "expectations", css_class="col-md-6"), Column(AppendedText( "contact", "<a href='%s' target='_blank'><span class='glyphicon glyphicon-plus'></span></a>" % reverse("contact_add")), "alignment", css_class="col-md-6"), css_class="row"), "active", self.submit) self.inline_helper.layout = Layout( Div(Column( "expectations", FieldWithButtons( "organisation", StrictButton( """<a href='#' onclick='$("#organisationForm").show("slow"); $("#organisation_input_group").hide("slow")'><span class='glyphicon glyphicon-plus'></span></a>""" ), css_id="organisation_input_group"), css_class="col-md-6"), Column( "alignment", FieldWithButtons( "contact", StrictButton( """<a href='#' onclick='$("#contactForm").show("slow"); $("#contact_input_group").hide("slow")'><span class='glyphicon glyphicon-plus'></span></a>""" ), css_id="contact_input_group"), css_class="col-md-6"), css_class="row"), )
def __init__(self, *args, **kwargs): super(LanguageForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-sm-5 col-md-5 col-lg-5' self.helper.field_class = 'col-sm-4 col-md-4 col-lg-4' self.helper.layout = Layout( FieldWithButtons( 'language', StrictButton( 'Change language <span class="glyphicon glyphicon-refresh"></span>', type='submit', name='change_language', css_class="btn-success"), ), )
def __init__(self, *args, **kwargs): super(WaitingListCompanyForm, self).__init__(*args, **kwargs) waiting_lists = Package.objects.filter( is_full=True, has_waiting_list=True ).exclude(companies=self.instance) self.fields["waiting_for_package"].queryset = waiting_lists self.fields["waiting_for_package"].help_text = None self.helper = FormHelper() self.helper.layout = Layout( FieldWithButtons( "waiting_for_package", StrictButton(_("Save"), type="submit", css_class="btn-success"), ) )
def __init__(self, *args, **kwargs): super(ListViewSearchForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_tag = True self.helper.form_method = 'get' self.helper.render_required_fields = True self.helper.form_show_labels = False self.helper.html5_required = True self.helper.form_id = 'search-form' self.helper.form_class = 'form-inline' self.helper.field_template = 'bootstrap3/layout/inline_field.html' self.helper.layout = Layout( FieldWithButtons( Field('q', css_class="input-sm"), Submit('submitBtn', _('Search'), css_class='btn-sm')), )
def __init__(self, *args, **kwargs): super(ListWithSearchForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.form_class = 'form-inline' self.helper.form_method = 'GET' self.helper.layout = Layout( Field('o'), FieldWithButtons( Field('q', placeholder=_('Filtrar Lista'), css_class='input-lg'), StrictButton(_('Filtrar'), css_class='btn-outline-primary btn-lg', type='submit')))
def __init__(self, *args, **kwargs): super(SubscriberCreditUpdateForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'id-SubscriberCreditUpdateForm' self.helper.form_method = 'post' params = { 'imsi': kwargs.get('initial').get('imsi') } self.helper.form_action = urlresolvers.reverse( 'subscriber-adjust-credit', kwargs=params) self.helper.form_class = 'col-xs-12 col-md-10 col-lg-8' self.helper.layout = Layout( 'imsi', FieldWithButtons('amount', StrictButton('Add', css_class='btn-default', type='submit')))
def __init__(self, *args, **kwargs): super(StatesSearchForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'get' self.helper.form_action = reverse('monitoring_all_states') self.helper.form_class = 'navbar-form' self.helper.form_show_labels = False self.helper.form_show_errors = False self.helper.layout = Layout( FieldWithButtons( Field('q', placeholder='Search', css_class='search'), StrictButton( '<span class="glyphicon glyphicon-search"></span>', type='submit', css_class='btn-default'), ))
class SearchForm(forms.Form): search = forms.CharField( label='Search', required=False, ) helper = FormHelper() helper.form_method = 'post' helper.form_show_labels = False helper.form_class = 'pull-right col-sm-3 col-md-4' helper.layout = Layout( FieldWithButtons( Field('search', placeholder='Search...'), StrictButton('<span class="glyphicon glyphicon-search"></span>', type='submit', css_class='btn btn-primary')), )
class SearchForm(forms.Form): search = forms.CharField( label='Search', required=False, ) helper = FormHelper() helper.form_method = 'post' helper.form_show_labels = False helper.form_class = 'float-right col-sm-3 col-md-4' helper.layout = Layout( FieldWithButtons( Field('search', placeholder='Search...', css_class="form-control"), StrictButton('<i class="fas fa-search"></i>', type='submit', css_class='btn btn-outline-dark') ), )
def __init__(self, *args, **kwargs): super(HeaderSearchForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = "GET" self.helper.form_action = 'orb_search' self.helper.form_show_labels = False self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-lg-1' self.helper.field_class = 'col-lg-4 navbar-right' self.helper.layout = Layout( FieldWithButtons('q', Submit('submit', _(u"Search"), css_class='btn btn-default')), Row(HTML(u"<a href='{0}'>{1}</a>".format( reverse('orb_search_advanced'), _(u"Advanced search"), )), css_class="advanced-search-link hidden-xs") )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper.form_method = 'POST' self.helper.layout = Layout( FieldWithButtons( 'container_serial_number', StrictButton('<i class="fa fa-barcode"></i> Scan', css_class="btn-info", css_id="on-scanner")), 'container_description', 'warehouse', Row( Column('bay', css_class='form-group col-md-4 mb-0'), Column('row', css_class='form-group col-md-4 mb-0'), Column('column', css_class='form-group col-md-4 mb-0'), css_class='form-row' ), Submit('submit', 'Update', css_class='btn btn-info col-md-3') )
def __init__(self, *args, **kwargs): super(QSearchFormSnippets, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_class = 'form-inline' self.helper.form_method = 'get' self.helper.form_action = '.' self.helper.layout = Layout( FieldWithButtons( 'q', StrictButton( _('Buscar por titulo del snippet'), type='submit', css_class='btn btn-primary' ) ) )
def __init__(self, *args, **kwargs): super(ClientConversionFilterForm, self).__init__(*args, **kwargs) conversions = (('none', 'Select Tracking Conversion'), ('none2method', 'No Method to Method'), ('traditional2method', 'Traditional Method to Method'), ('method2method', 'Method to Method')) self.fields['conversions'].choices = conversions self.helper = FormHelper() self.helper.layout = Layout( Row( FieldWithButtons( 'conversions', Submit('submit', _(u'Go'), css_class='btn btn-default'), Reset('Reset', _(u'Reset'), css_class='btn btn-primary')), ))
def __init__(self, *args, **kwargs): super(AnswerForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_class = 'form-horizontal' self.helper.form_tag = False self.helper.add_input(Submit('submit', 'Submit')) self.fields['correct'].widget = HiddenInput() button_text = 'Correct' if self.fields[ 'correct'].initial == 'Correct' else 'Incorrect' button_css = 'correct-button btn-success' if self.instance.correct else 'correct-button btn-danger' # ng-click="toggleCorrect()"' self.helper.layout = Layout( FieldWithButtons( 'answer', StrictButton(button_text, css_class=button_css, ng_click="toggleCorrect()")))
def __init__(self, *args, **kwargs): super(StudentForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.form_method = 'POST' self.helper.form_class = 'form-horizontal' #add form or edit form if kwargs['instance'] is None: add_form = True else: add_form = False # set form tag attributes if add_form: self.helper.form_action = reverse('students_add') else: self.helper.form_action = reverse('students_edit', kwargs={'pk': kwargs['instance'].id}) # set form field properties self.helper.help_text_inline = True self.helper.html5_required = True self.helper.label_class = 'col-sm-2 control-label' self.helper.field_class = 'col-sm-8' # add buttons if add_form: submit = Submit('add_button', u'Добавить', css_class="btn btn-primary") else: submit = Submit('save_button', u'Сохранить', css_class="btn btn-primary") self.helper.layout = Layout( 'first_name', 'last_name', 'middle_name', #Submit('dat','',css_class="glyphicon glyphicon-calendar"), FieldWithButtons('birthday',StrictButton('',css_class="glyphicon glyphicon-calendar")), 'photo', 'ticket', 'student_group', 'notes', FormActions(submit,Submit('cancel_button', u'Отменить', css_class="btn btn-link")) )
def __init__(self, *args, **kwargs): super(FormForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.form_tag = False self.helper.layout = Layout( Div( Field('title', css_class='input-xlarge'), Field('instructions', css_class='span5', rows=3), Field('confirmation_text', css_class='span5', rows=3), FieldWithButtons( Field('end_date', css_class="input-small end-date", placeholder="never"), StrictButton("<i class='icon-calendar'></i>", css_class="btn-datepicker")), Field('collect_users'), ), )
def __init__(self, data=None, source='', sensor=None, **kwargs): from crispy_forms.bootstrap import FieldWithButtons from crispy_forms.layout import Layout, Submit, Field super().__init__(data, source, sensor, **kwargs) if sensor.is_finite_range: field = self.fields['status'] field.sensor_name = sensor.name field.min_value = self.num_type(sensor.value_min) field.max_value = self.num_type(sensor.value_max) if self.num_type is int: field.step = 1 else: field.step = (sensor.value_max - sensor.value_min) / 1000. self.helper.layout = Layout('name', Field('status', template='slider.html')) else: self.helper.layout = Layout('name', FieldWithButtons('status', Submit('set_status', '>')))
def __init__(self, *args, **kwargs): self.user = kwargs.pop('user', None) super(JoinTeamForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_action = 'join_team' self.helper.layout = Layout( Fieldset( 'Join team', HTML( """<span style='color: grey;'>If you want to join a team that already exists, ask somebody already on the team for the team code. It will be on their account page.</span> <br/><br/>"""), FieldWithButtons(Field('code', placeholder='Team code'), StrictButton('Join team', css_class='btn-success', type='submit')) ) )
def __init__(self, *args, **kwargs): super(UpdateCaseGroupForm, self).__init__(*args, **kwargs) self.fields['name'].label = "" self.helper.form_style = 'inline' self.helper.form_method = 'post' self.helper.form_show_labels = True self.helper.layout = Layout( 'item_id', 'action', FieldWithButtons( Field('name', placeholder="Group Name"), StrictButton( _("Update Group Name"), css_class='btn-primary', type="submit", )), )
def __init__(self, *args, **kwargs): yaml_layout = kwargs.pop('yaml_layout') q_field = Div( FieldWithButtons( Field('q', placeholder=_('Filtrar Lista'), autocomplete='off', type='search', onkeypress='atualizaContatos(event)'), StrictButton(_('Filtrar'), css_class='btn-outline-primary', type='button', onclick='atualizaContatos(event)')), Div(css_class='form-group-contato-search')) q = [ _('Seleção de Contatos'), [(q_field, 5), (Div(Field('contatos'), css_class='form-group-contatos'), 7)] ] yaml_layout.append(q) self.helper = FormHelper() self.helper.field_class = 'controls' self.helper.layout = SaplFormLayout(*yaml_layout) super(GrupoDeContatosForm, self).__init__(*args, **kwargs) self.fields['q'].help_text = _('Digite parte do nome, nome social ou ' 'apelido do Contato que você procura.') self.fields['contatos'].widget = forms.CheckboxSelectMultiple() self.fields['contatos'].queryset = Contato.objects.all() self.fields['contatos'].choices = [ (c.pk, c) for c in self.instance.contatos.order_by('nome')]\ if self.instance.pk else [] self.fields['contatos'].help_text = _( 'Procure por Contatos na caixa de buscas e arraste ' 'para esta caixa os Contatos interessados neste Processo.')
def test_field_with_buttons(self, settings): form = SampleForm() form.helper = FormHelper() form.helper.layout = Layout( FieldWithButtons( Field("password1", css_class="span4"), StrictButton("Go!", css_id="go-button"), StrictButton("No!", css_class="extra"), StrictButton("Test", type="submit", name="whatever", value="something"), css_class="extra", autocomplete="off", input_size="input-group-sm", )) assert parse_form(form) == parse_expected( f"{settings.CRISPY_TEMPLATE_PACK}/test_layout_objects/test_field_with_buttons.html" )
def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.form_tag = False self.helper.disable_csrf = True row_id = kwargs.pop('row_id') self.helper.layout = Layout( Div( Div(HTML("<h5>Basics</h5>"), Field('measurement', id='id_measurements_{0}'.format(row_id), type='hidden'), Field('obs_parameter', id='id_obs_parameter_{0}'.format(row_id)), Div(FieldWithButtons( Field('new_parameter', id='id_new_parameter_{0}'.format(row_id)), StrictButton( "Add", onclick=("commitNewParam(" "'#id_new_parameter_{0}'," "{0}," "'#kit-form-{0} div.kit-container')". format(row_id))), ), css_class='hide new-parameter'), Field('value', id='id_value_{0}'.format(row_id)), css_class='param-row span6', css_id='param-form-{0}'.format(row_id)), Div( HTML("<h5>Test specifics</h5>"), Div(css_class='kit-container'), css_class='kit-row span6', css_id='kit-form-{0}'.format(row_id), ), css_class='row-fluid', css_id='test-value-row-{0}'.format(row_id), )) super(ParamRowForm, self).__init__(*args, **kwargs) self.fields['obs_parameter'].choices = [('', 'Select one')] + [ (p, p) for p in Parameter.objects.all().values_list('name', flat=True) ] + [('__NEW__', 'Add new...')]
def __init__(self, *args, **kwargs): # call original initializator super(StudentForm, self).__init__(*args, **kwargs) # this helper object allows us to customize form self.helper = FormHelper(self) # form tag attributes #<span class="input-group-addon"> # <span class="glyphicon glyphicon-calendar"></span> #</span> #self.helper.form_action = reverse('students_edit', kwargs={'pk': kwargs['instance'].id}) self.helper.form_method = 'POST' self.helper.form_class = 'form-horizontal' # set form field properties self.helper.help_text_inline = True #self.helper.html5_required = True self.helper.label_class = 'col-sm-2 control-label' self.helper.field_class = 'col-sm-10' self.helper.layout = Layout( Field('first_name', placeholder=u"Ім'я студента"), Field('last_name', placeholder=u"Прізвище студента"), Field('middle_name', placeholder=u"Ім'я по-батькові студента"), FieldWithButtons( 'birthday', StrictButton( '<span class="glyphicon glyphicon-calendar"></span>', id='calend')), #Field('birthday', placeholder=u"Ваш день народження"), Field('photo'), Field('ticket', placeholder=u"Номер студентського квитка"), Field('student_group'), Field('notes', placeholder=u"Додаткові нотатки")) #ordering field 'student_group' at form by tittle self.fields['student_group'].queryset = Group.objects.order_by( 'tittle') # add buttons self.helper.add_input( Submit('add_button', u'Зберегти', css_class="btn btn-primary")) self.helper.add_input( Submit('cancel_button', u'Скасувати', css_class="btn btn-link"))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['date'].widget.attrs['class'] = 'form-control-sm' self.fields['date'].widget.attrs['style'] = 'text-align: center;' self.fields['date'].widget.attrs['value'] = timezone.now().strftime( '%Y-%m-%d') self.helper = FormHelper() self.helper.form_method = 'post' self.helper.form_tag = False self.helper.disable_csrf = True self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-3 h5' self.helper.field_class = 'col-6' self.helper.layout = Layout( Div(FieldWithButtons('date', StrictButton( '<i class="far fa-calendar-alt"></i>', css_class='btn-sm btn-date'), css_class='form-control-sm'), css_class='col-4 p-0 mt-3'), )