class CompaniesHouseBusinessDetailsForm(forms.Form): company_name = forms.CharField(label='Registered company name') company_number = forms.CharField( required=False, container_css_classes= 'border-active-blue read-only-input-container js-disabled-only') sector = forms.ChoiceField( label='Which industry are you in?', choices=INDUSTRY_CHOICES, container_css_classes='govuk-!-margin-top-6 govuk-!-margin-bottom-6', ) percentage_uk_market = forms.CharField( label= 'What percentage of the total UK market do your sales represent? (optional)', required=False, ) employees = forms.ChoiceField( label='Number of employees', choices=choices.EMPLOYEES, required=False, widget=forms.RadioSelect(), ) turnover = forms.ChoiceField( label='Annual turnover for 2018-2019', choices=TURNOVER_CHOICES, required=False, widget=forms.RadioSelect(), )
class FeedbackForm(SaveOnlyInDatabaseAPIForm): result_found = forms.ChoiceField( label='Did you find what you were looking for on the site today?', widget=forms.RadioSelect(), choices=[('yes', 'Yes'), ('no', 'No')]) search_target = forms.CharField( label= 'Whether yes or no, please let us know what you were searching for', widget=Textarea(attrs={ 'rows': 4, 'cols': 15 })) from_search_query = forms.CharField(widget=HiddenInput(), required=False) from_search_page = IntegerField(widget=HiddenInput(), required=False) contactable = forms.ChoiceField( label= 'May we contact you with some brief follow-up questions on your experience?', widget=forms.RadioSelect(), choices=[('yes', 'Yes'), ('no', 'No')]) contact_name = forms.CharField(label='What is your name?', required=False) contact_email = forms.EmailField(label='What is your email address?', required=False) contact_number = forms.CharField( label='What is your phone number? (optional)', required=False) captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3()) @property def serialized_data(self): if 'captcha' in self.cleaned_data: del self.cleaned_data['captcha'] return self.cleaned_data
class RadioForm(PrefixIdMixin, forms.Form): radio = forms.ChoiceField( label='Q1: Radio select', label_suffix='', help_text='Some help text.', widget=forms.RadioSelect(use_nice_ids=True, attrs={'id': 'radio-one'}), choices=( (True, 'Yes'), (False, 'No'), )) radio_group = forms.ChoiceField( label='Q2: Radio select with option groups', label_suffix='', help_text='Some help text.', widget=forms.RadioSelect(use_nice_ids=True, attrs={'id': 'radio-two'}), choices=( ('Colours', ( ('red', 'Red'), ('green', 'Green'), ('blue', 'Blue'), )), ('Numbers', ( ('4', 'Four'), ('5', 'Five'), ('6', 'Six'), )), ))
class SellingOnlineOverseasApplicantNonCH(forms.Form): company_name = forms.CharField( label='Company name', disabled=True, required=False, container_css_classes='border-active-blue read-only-input-container', ) company_address = forms.CharField( label='Address', disabled=True, required=False, container_css_classes= 'border-active-blue read-only-input-container padding-bottom-0 margin-bottom-30', ) website_address = forms.CharField( label='Your business web address', help_text='Website address, where we can see your products online.', max_length=255, ) turnover = forms.ChoiceField( label='Your business turnover last year', help_text=( 'You may use 12 months rolling or last year\'s annual turnover.'), choices=SOO_TURNOVER_OPTIONS, widget=forms.RadioSelect(), )
def test_radio_select_class_has_attrs(): radio = forms.RadioSelect( attrs={'id': 'radio-test'} ) assert radio.input_type == 'radio' assert radio.css_class_name == 'select-multiple' assert radio.attrs['id'] == 'radio-test'
class BusinessDetailsForm(fields.BindNestedFormMixin, forms.Form): company_type = forms.ChoiceField( label='Company type', label_suffix='', widget=forms.RadioSelect(), choices=COMPANY_TYPE_CHOICES, ) company_name = forms.CharField(label='Company name') company_number = forms.CharField( required=False, container_css_classes='form-group js-disabled-only') sector = forms.ChoiceField( label='Which industry are you in?', choices=INDUSTRY_CHOICES, ) employees = forms.ChoiceField( label='Number of employees', choices=(('', 'Please select'), ) + choices.EMPLOYEES, required=False, ) turnover = forms.ChoiceField( label='Annual turnover for 2018-19', choices=TURNOVER_CHOICES, required=False, ) employment_regions = fields.MultipleChoiceAutocomplateField( label='Where do you employ the most people?', choices=choices.EXPERTISE_REGION_CHOICES, )
class InternationalContactForm(SerializeDataMixin, GovNotifyEmailActionMixin, forms.Form): ORGANISATION_TYPE_CHOICES = ( ('COMPANY', 'Company'), ('OTHER', 'Other type of organisation'), ) given_name = forms.CharField() family_name = forms.CharField() email = forms.EmailField(label='Email address') organisation_type = forms.ChoiceField(label_suffix='', widget=forms.RadioSelect(), choices=ORGANISATION_TYPE_CHOICES) organisation_name = forms.CharField(label='Your organisation name') country_name = forms.ChoiceField(choices=[('', 'Please select')] + choices.COUNTRY_CHOICES, ) city = forms.CharField(label='City') comment = forms.CharField( label='Tell us how we can help', help_text=('Do not include personal information or anything of a ' 'sensitive nature'), widget=Textarea, ) captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3()) terms_agreed = forms.BooleanField(label=TERMS_LABEL)
class ConsumerTypeForm(forms.Form): consumer_type = forms.ChoiceField( label='', choices=( (constants.CONSUMER_GROUP, 'Consumer group'), (constants.INDIVIDUAL_CONSUMER, 'Individual consumer'), ), widget=forms.RadioSelect(), )
class InternationalRoutingForm(forms.Form): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['choice'].choices = international_choices() choice = forms.ChoiceField( label='', widget=forms.RadioSelect(), choices=[], # array overridden by constructor )
class OutcomeForm(forms.Form): CHOICES = (('INCREASE', "I want an increase in the tariff rate"), ('DECREASE', "I want a decrease in the tariff rate"), ('QUOTA_CHANGE', "I want the tariff quote changed"), ('OTHER', 'Other')) outcome = forms.ChoiceField( label='', widget=forms.RadioSelect(), choices=CHOICES, )
class LocationRoutingForm(forms.Form): CHOICES = ( (constants.DOMESTIC, 'The UK'), (constants.INTERNATIONAL, 'Outside the UK'), ) choice = forms.ChoiceField( label='', widget=forms.RadioSelect(), choices=CHOICES, )
class GreatAccountRoutingForm(forms.Form): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['choice'].choices = great_account_choices() choice = forms.ChoiceField( label='', widget=forms.RadioSelect(), choices=[], # array overridden by constructor )
class OutcomeForm(fields.BindNestedFormMixin, forms.Form): tariff_rate = forms.ChoiceField( label='Tariff rate change', choices=[ (constants.INCREASE, 'I want the tariff rate increased'), (constants.DECREASE, 'I want the tariff rate decreased'), ('N/A', 'I want neither'), ], widget=forms.RadioSelect(), ) tariff_quota = forms.ChoiceField( label='Tariff quota change', choices=[ (constants.INCREASE, 'I want the tariff quota increased '), (constants.DECREASE, 'I want the tariff quota decreased'), ('N/A', 'I want neither'), ], widget=forms.RadioSelect(), )
class LocationRoutingForm(forms.Form): CHOICES = ( (constants.UK_BUSINESS, "I'm a UK business importing from overseas"), (constants.UK_CONSUMER, "I'm a UK consumer or consumer group"), (constants.FOREIGN, "I'm an exporter from a developed country"), ) choice = forms.ChoiceField( label='', widget=forms.RadioSelect(), choices=CHOICES, )
class ExportOpportunitiesRoutingForm(forms.Form): CHOICES = ( (constants.NO_RESPONSE, 'I haven\'t had a response from the opportunity I applied for'), (constants.ALERTS, 'My daily alerts are not relevant to me'), (constants.OTHER, 'Other'), ) choice = forms.ChoiceField( label='', widget=forms.RadioSelect(), choices=CHOICES, )
class GreatServicesRoutingForm(forms.Form): CHOICES = ( (constants.EXPORT_OPPORTUNITIES, 'Export opportunities service'), (constants.GREAT_ACCOUNT, 'Your account on great.gov.uk'), (constants.OTHER, 'Other'), ) choice = forms.ChoiceField( label='', widget=forms.RadioSelect(), choices=CHOICES, )
def test_radio_select_widget(): widget = forms.RadioSelect( attrs={'id': 'radio-test'}, choices=TEST_CHOICES ) html = widget.render('name', 'value') soup = BeautifulSoup(html, 'html.parser') assert '<label ' in html assert '<ul ' in html list_element = soup.find('ul') assert list_element['id'] == 'radio-test'
class DomesticContactForm(FieldsMutationMixin, SerializeMixin, ZendeskActionMixin, ConsentFieldMixin, forms.Form): first_name = forms.CharField() last_name = forms.CharField() email = forms.EmailField() organisation_type = forms.ChoiceField(label_suffix='', widget=forms.RadioSelect(), choices=COMPANY_CHOICES) company_name = forms.CharField() comment = forms.CharField(widget=Textarea, validators=[no_html, not_contains_url_or_email]) captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
def test_widget_id_handles_spaces_and_uppercase(): widget = forms.RadioSelect( use_nice_ids=True, attrs={'id': 'radio-test'}, choices=TEST_CHOICES_WITH_SPACES ) html = widget.render('name', 'value') soup = BeautifulSoup(html, 'html.parser') exp_ids = ['cyan-colour', 'magenta-colour', 'yellow-colour'] inputs = soup.find_all('input') for input, exp_id in zip(inputs, exp_ids): assert input.attrs['id'] == 'radio-test-{}'.format(exp_id)
class AboutForm(forms.Form): error_css_class = 'input-field-container has-error' CATEGORY_CHOICES = ( 'I’m an exporter or investor, or I want to export or invest', 'I work for a trade association', 'Other') firstname = forms.CharField( label='First name', error_messages={'required': 'Enter your first name'}) lastname = forms.CharField( label='Last name', error_messages={'required': 'Enter your last name'}) jobtitle = forms.CharField( label='Job title', error_messages={'required': 'Enter your job title'}) business_type = forms.ChoiceField( label='Business type', widget=forms.RadioSelect( attrs={'id': 'checkbox-single'}, use_nice_ids=True, ), choices=((choice, choice) for choice in CATEGORY_CHOICES), error_messages={'required': 'Tell us your business type'}) other_business_type = forms.CharField( label='Tell us about your organisation', widget=TextInput(attrs={'class': 'js-field-other'}), required=False) company_name = forms.CharField( label='Business or organisation name', error_messages={ 'required': 'Enter your business or organisation name' }) email = forms.EmailField( label='Email address', error_messages={'required': 'Enter your email address'}) phone = forms.CharField( label='Telephone number', error_messages={'required': 'Enter your telephone number'}) def clean(self): data = self.cleaned_data other_business_type = data.get('other_business_type') business_type = data.get('business_type') if business_type == 'Other' and not other_business_type: self.add_error('other_business_type', 'Enter your organisation') else: return data
class RoutingUserTypeForm(forms.Form): CHOICES = ( (constants.UK_BUSINESS, "As a UK business or trade organisation"), (constants.UK_CONSUMER, "As a UK consumer or consumer representative"), (constants.DEVELOPING_COUNTRY_COMPANY, ("As an exporter, or representative, from a developing country eligible" " for the Generalised Scheme of Preferences (GSP) or with an Economic Partnership" " Agreement (EPA) with the UK.")), ) choice = forms.ChoiceField( label='', widget=forms.RadioSelect(), choices=CHOICES, )
class BusinessDetailsForm(ConsentFieldMixin, forms.Form): TURNOVER_OPTIONS = (('', 'Please select'), ('0-25k', 'under £25,000'), ('25k-100k', '£25,000 - £100,000'), ('100k-1m', '£100,000 - £1,000,000'), ('1m-5m', '£1,000,000 - £5,000,000'), ('5m-25m', '£5,000,000 - £25,000,000'), ('25m-50m', '£25,000,000 - £50,000,000'), ('50m+', '£50,000,000+')) company_type = forms.ChoiceField( label_suffix='', widget=forms.RadioSelect(), choices=COMPANY_TYPE_CHOICES, ) companies_house_number = forms.CharField( label='Companies House number', required=False, ) company_type_other = forms.ChoiceField( label_suffix='', choices=(('', 'Please select'), ) + COMPANY_TYPE_OTHER_CHOICES, required=False, ) organisation_name = forms.CharField() postcode = forms.CharField() industry = forms.ChoiceField(choices=INDUSTRY_CHOICES) industry_other = forms.CharField( label='Type in your industry', widget=TextInput(attrs={'class': 'js-field-other'}), required=False, ) turnover = forms.ChoiceField( label='Annual turnover (optional)', choices=TURNOVER_OPTIONS, required=False, ) employees = forms.ChoiceField( label='Number of employees (optional)', choices=(('', 'Please select'), ) + choices.EMPLOYEES, required=False, ) captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3()) def clean_industry(self): industry = self.cleaned_data['industry'] self.cleaned_data['industry_label'] = INDUSTRY_MAP[industry] return industry
def test_radio_default_ids(): widget = forms.RadioSelect( attrs={'id': 'radio-test'}, choices=TEST_CHOICES ) html = widget.render('name', 'value') soup = BeautifulSoup(html, 'html.parser') list_items = soup.find_all('input') exp_ids = [ 'radio-test_0', 'radio-test_1', 'radio-test_2', ] for item, exp_id in zip(list_items, exp_ids): assert item.attrs['id'] == exp_id
def test_radio_nice_ids(): widget = forms.RadioSelect( use_nice_ids=True, attrs={'id': 'radio-test'}, choices=TEST_CHOICES ) html = widget.render('name', 'value') soup = BeautifulSoup(html, 'html.parser') list_items = soup.find_all('input') exp_ids = [ 'radio-test-cyan', 'radio-test-magenta', 'radio-test-yellow', ] for item, exp_id in zip(list_items, exp_ids): assert item.attrs['id'] == exp_id
class DomesticRoutingForm(forms.Form): CHOICES = ( (constants.TRADE_OFFICE, 'Find your local trade office'), (constants.EXPORT_ADVICE, 'Advice to export from the UK'), (constants.GREAT_SERVICES, 'great.gov.uk account and services support'), (constants.FINANCE, 'UK Export Finance (UKEF)'), (constants.EUEXIT, EU_EXIT_LABEL), (constants.EVENTS, 'Events'), (constants.DSO, 'Defence and Security Organisation (DSO)'), (constants.OTHER, 'Other'), ) choice = forms.ChoiceField( label='', widget=forms.RadioSelect(), choices=CHOICES, # possibly update by mixin )
class SellingOnlineOverseasApplicantDetails(forms.Form): sku_count = IntegerField( label='How many stock keeping units (SKUs) do you have?', help_text=( 'A stock keeping unit is an individual item, such as a product ' 'or a service that is offered for sale.'), widget=TextInput(attrs={'class': 'short-field'}), ) trademarked = TypedChoiceField( label='Are your products trademarked in your target countries?', help_text=( 'Some marketplaces will only sell products that are trademarked.'), label_suffix='', coerce=lambda x: x == 'True', choices=[(True, 'Yes'), (False, 'No')], widget=forms.RadioSelect(), required=False, )
class SellingOnlineOverseasApplicantIndividual(forms.Form): company_name = forms.CharField(label='Business name', ) company_number = forms.CharField( label='Companies House number (optional)', ) company_address = forms.CharField(label='Address', ) company_postcode = forms.CharField(label='Post code', ) website_address = forms.CharField( label='Your business web address', help_text='Website address, where we can see your products online.', max_length=255, ) turnover = forms.ChoiceField( label='Your business turnover last year', help_text=( 'You may use 12 months rolling or last year\'s annual turnover.'), choices=SOO_TURNOVER_OPTIONS, widget=forms.RadioSelect(), )
class InternationalContactForm(FieldsMutationMixin, SerializeMixin, ZendeskActionMixin, forms.Form): first_name = forms.CharField() last_name = forms.CharField() email = forms.EmailField() organisation_type = forms.ChoiceField( label_suffix='', widget=forms.RadioSelect(), choices=COMPANY_CHOICES, ) company_name = forms.CharField() country = forms.ChoiceField( choices=[('', 'Please select')] + choices.COUNTRY_CHOICES, widget=Select(), ) city = forms.CharField() comment = forms.CharField(widget=Textarea, validators=[no_html, not_contains_url_or_email]) captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3()) terms_agreed = forms.BooleanField(label=TERMS_LABEL)
class SellingOnlineOverseasExperience(forms.Form): EXPERIENCE_OPTIONS = (('Not yet', 'Not yet'), ('Yes, sometimes', 'Yes, sometimes'), ('Yes, regularly', 'Yes, regularly')) experience = forms.ChoiceField( label='Have you sold products online to customers outside the UK?', choices=EXPERIENCE_OPTIONS, widget=forms.RadioSelect(), ) description = forms.CharField( label='Pitch your business to this marketplace', help_text=( 'Your pitch is important and the information you provide may be ' 'used to introduce you to the marketplace. You could describe ' 'your business, including your products, your customers and ' 'how you market your products in a few paragraphs.'), widget=Textarea, )
class DemoFormErrors(PrefixIdMixin, forms.Form): text_field1 = forms.CharField(label='Simple text field', help_text='Some help text', required=True) checkbox1 = forms.BooleanField( label='Label text', required=True, help_text=('Some help text.'), widget=forms.CheckboxWithInlineLabel(attrs={'id': 'checkbox-one'})) multiple_choice = forms.MultipleChoiceField( label='Multiple choice checkboxes', required=True, help_text='Some help text.', widget=forms.CheckboxSelectInlineLabelMultiple( attrs={'id': 'checkbox-multiple'}, use_nice_ids=True, ), choices=( ('red', 'Red'), ('green', 'Green'), ('blue', 'Blue'), ), ) radio = forms.ChoiceField( label='Radio select', required=True, label_suffix='', help_text='Some help text.', widget=forms.RadioSelect(use_nice_ids=True, attrs={'id': 'radio-one'}), choices=( (True, 'Yes'), (False, 'No'), )) def clean(self, *args, **kwargs): self.add_error( field=None, error=['Some non-field error', 'Some other non-field error']) super().clean(*args, **kwargs)