Button

class crispy_forms_gds.layout.Button(name, value, disabled=False, **kwargs)

Create a button of any type.

Buttons are rendered by default as Design System primary buttons. When dealing with the basic objects you will need to pass the appropriate css class to get them to display as secondary or warning buttons.

Examples:

Button('add', 'Add contact')
Button('cancel', 'Cancel', css_class="govuk-button--secondary")
Button('delete', 'Delete account', css_class="govuk-button--warning")

To save some typing there are class methods which save you the trouble of setting the css class:

Button.primary('add', 'Add contact')
Button.secondary('cancel', 'Cancel')
Button.warning('delete', 'Delete account')

Buttons are disabled by setting the disabled attribute to true:

Button.primary('add', 'Add contact', disabled=True)
Parameters
  • name (str) – the value sent when the form is submitted.

  • value (str) – the button’s title.

  • disabled (bool, optional) – is the button disabled. The default is False.

  • css_id (str, optional) – an unique identifier for the <button>. Generally you will need to set this only if you need to add some javascript or very specific styling.

  • css_class (str, optional) – the names of one or more CSS classes that will be added to the <button>. The basic Design System CSS class, govuk-button is added automatically. This parameter is for any extra styling you want to apply.

  • template (str, optional) – the path to a template that overrides the one normally used.

  • **kwargs – any additional attributes you want to add to the <button>.

Submit

class crispy_forms_gds.layout.Submit(name, value, **kwargs)

Create a Submit button.

Submit buttons are rendered as input[type=submit] elements and work exactly the same way as primary Buttons. This is not a Design System component however it is included as it’s a basic element of django-crispy-forms.

Examples:

Submit('add', 'Add contact')
Submit('add', 'Add contact', disabled=True)
Parameters
  • name (str) – the value sent when the form is submitted.

  • value (str) – the button’s title.

  • disabled (bool, optional) – is the button disabled. The default is False.

  • css_id (str, optional) – an unique identifier for the <input> element. Generally you will need to set this only if you need to add some javascript or very specific styling.

  • css_class (str, optional) – the names of one or more CSS classes that will be added to the <input> element. The basic Design System CSS class, govuk-button is added automatically. This parameter is for any extra styling you want to apply.

  • template (str, optional) – the path to a template that overrides the one normally used.

  • **kwargs – any additional attributes you want to add to the <input> element.