Button Widgets#
- class Button(text: Optional[str] = None, color: Optional[str] = None, close: Optional[bool] = None, size: Optional[str] = None, disabled: Optional[bool] = None, **kwargs)[source]#
Bases:
Block
Render a
<button>
with Bootstrap styling.Example
>>> button = Button(text="My Button")
When rendered in the template with the
wildewdigets
template tag, this will produce:<button type="button" class="button btn btn-secondary">My Button</button>
- Keyword Arguments:
text – The text to use for the button
color – The Boostrap color class to use for the button
close – The Boostrap close icon will be used for the button
size – The Bootstrap button size - None, ‘sm’, ‘lg’
disabled – If
True
, the button will be disabled
- block: str = 'button'#
block is the official wildewidgets name of the block; it can’t be changed by constructor kwargs
- close: bool = False#
If
True
, ignoretext
and make this into a Bootstrap “close” button with a close icon.
- class CollapseButton(target: Optional[str] = None, **kwargs)[source]#
Bases:
Button
Render a
<button>
with Bootstrap styling which toggles acollapse
.Example
>>> button = CollapseButton(text="My Button", target='#mymodal')
When rendered in the template with the
wildewdigets
template tag, this will produce:<button type="button" class="button button--collapse btn btn-secondary" data-toggle="collapse" data-target="#mymodal" aria-expanded="false aria-controls="mymodal">My Button</button>
- Keyword Arguments:
target – The CSS target for the Bootstrap collapse
- class FormButton(**kwargs)[source]#
Bases:
Block
Render a
<form>
with optional hidden inputs and a submit button.Example:
>>> button = FormButton( text="Save", action='/my/form/action', data={'field1': 'value1'} )
When rendered in the template with the
wildewdigets
template tag, this will produce:<form action="/my/form/action" method="post" class="button-form"> <input type="hidden" name="csrfmiddlewaretoken" value="__THE_CSRF_TOKEN__"> <input type="hidden" name="field1" value="value1"> <input type="submit" class="button button--submit btn btn-secondary" value="Save"> </form>
All the constructor parameters can be set in a subclass of this class as class attributes. Parameters to the constructor override any defined class attributes.
- Keyword Arguments:
text – The text to use for the button, defaults to ‘Button’
color – The Boostrap color class to use for the button, defaults to ‘secondary’
button_css_class – a string of classes to apply to the button, defaults to no classes.
button_attributes – Set any additional attributes for the button as key, value pairs, defaults to no additional attributes.
button_data_attributes – Set
data-
attributes for the button, defaults to no data attributes
- get_context_data(*args, **kwargs) → Dict[str, Any][source]#
Update the template context dictionary used when rendering this block.
- Keyword Arguments:
**kwargs – the current context dictionary
- Returns:
The updated context dictionary
- class InputButton(confirm_text: Optional[str] = None, **kwargs)[source]#
Bases:
Button
Render an
<input type="submit">
with Bootstrap button styling.Example:
>>> button = InputButton(text="Save")
When rendered in the template with the
wildewdigets
template tag, this will produce:<input type="submit" class="button button--submit btn btn-secondary" value="Save">
- class LinkButton(url: Optional[str] = None, **kwargs)[source]#
Bases:
Button
Render an
<a>
with Bootstrap button styling which toggles a Bootstrap modal.Example
>>> button = LinkButton(text="My Button", url='https://myexample.com')
When rendered in the template with the
wildewdigets
template tag, this will produce:<a href="https://myexample.com" class="button button--link btn btn-secondary">My Button</a>
- Keyword Arguments:
url – The URL for the
href
attribute of the <a> record, defaults to no URL.
- class ModalButton(target: Optional[str] = None, **kwargs)[source]#
Bases:
Button
Render a
<button>
with Bootstrap styling which toggles a Bootstrap modal.Example
>>> button = ModalButton(text="My Button", target='#mymodal')
When rendered in the template with the
wildewdigets
template tag, this will produce:<button type="button" class="button button--modal btn btn-secondary" data-toggle="modal" data-target="#mymodal">My Button</button>
- Keyword Arguments:
target – The CSS target for the Bootstrap modal