duck.html.components.input

Input components module.

Module Contents

Classes

BaseInput

Base Input component.

CSRFInput

Csrf Input component - This component is useful in situations where you don’t want to use the csrf_token tag. You only need to parse a request to generate csrfmiddleware field so as to avoid cross site request forgery attacks.

Input

Input component.

InputWithLabel

InputWithLabel component which contains a label alongside an input component.

API

class duck.html.components.input.BaseInput(element: Optional[str] = None, properties: Dict[str, str] = None, props: Dict[str, str] = None, style: Dict[str, str] = None, **kwargs)[source]

Bases: duck.html.components.NoInnerComponent

Base Input component.

Initialization

Initialize an HTML component.

Parameters:
  • element – The HTML element tag name (e.g., textarea, input, button). Can be None, but make sure element is returned by get_element method.

  • accept_inner_html – Whether the HTML component accepts an inner body (e.g., inner-body-here).

  • inner_html – Inner html to add to the HTML component. Defaults to None.

  • properties – Dictionary for properties to initialize the component with.

  • props – Just same as properties argument (added for simplicity).

  • style – Dictionary for style to initialize the component with.

  • **kwargs – Extra keyword arguments

Raises:

HtmlComponentError – If ‘element’ is not a string or ‘inner_html’ is set but ‘accept_inner_html’ is False.

get_element()[source]
on_create()[source]
class duck.html.components.input.CSRFInput(request: duck.http.request.HttpRequest)[source]

Bases: duck.html.components.input.Input

Csrf Input component - This component is useful in situations where you don’t want to use the csrf_token tag. You only need to parse a request to generate csrfmiddleware field so as to avoid cross site request forgery attacks.

Initialization

Initialize an HTML component.

Parameters:
  • element – The HTML element tag name (e.g., textarea, input, button). Can be None, but make sure element is returned by get_element method.

  • accept_inner_html – Whether the HTML component accepts an inner body (e.g., inner-body-here).

  • inner_html – Inner html to add to the HTML component. Defaults to None.

  • properties – Dictionary for properties to initialize the component with.

  • props – Just same as properties argument (added for simplicity).

  • style – Dictionary for style to initialize the component with.

  • **kwargs – Extra keyword arguments

Raises:

HtmlComponentError – If ‘element’ is not a string or ‘inner_html’ is set but ‘accept_inner_html’ is False.

on_create()[source]
class duck.html.components.input.Input(element: Optional[str] = None, properties: Dict[str, str] = None, props: Dict[str, str] = None, style: Dict[str, str] = None, **kwargs)[source]

Bases: duck.html.components.input.BaseInput

Input component.

Parameters:
  • type – The type of input, e.g. text, url, etc.

  • name – Name of the input component.

  • placeholder – Placeholder for input component.

  • required – Whether the field is required or not.

  • maxlength – The maximum allowed characters.

  • minlength – The minimum allowed characters.

  • disabled – Whether input is disabled.

Initialization

Initialize an HTML component.

Parameters:
  • element – The HTML element tag name (e.g., textarea, input, button). Can be None, but make sure element is returned by get_element method.

  • accept_inner_html – Whether the HTML component accepts an inner body (e.g., inner-body-here).

  • inner_html – Inner html to add to the HTML component. Defaults to None.

  • properties – Dictionary for properties to initialize the component with.

  • props – Just same as properties argument (added for simplicity).

  • style – Dictionary for style to initialize the component with.

  • **kwargs – Extra keyword arguments

Raises:

HtmlComponentError – If ‘element’ is not a string or ‘inner_html’ is set but ‘accept_inner_html’ is False.

on_create()[source]
class duck.html.components.input.InputWithLabel(element: Optional[str] = None, properties: Optional[Dict[str, str]] = None, props: Optional[Dict[str, str]] = None, style: Optional[Dict[str, str]] = None, inner_html: Optional[Union[str, str, float]] = None, children: Optional[List[duck.html.components.HtmlComponent]] = None, **kwargs)[source]

Bases: duck.html.components.container.FlexContainer

InputWithLabel component which contains a label alongside an input component.

Parameters:
  • label_text – Text for the label

  • input – Any html component (e.g fileinput.FileDragAndDrop), preferrebly Input component.

Example Usage:

fullname = InputWithLabel(
    label_text="Full Name", # Or use label_html
    input=Input(
        type="text",
        name="fullname",
        placeholder="Full Name",
        required=True,
        maxlength=64,
    )
)

email = InputWithLabel(
    label_text="Email",
    input=Input(
        type="email",
        name="email",
        placeholder="Email",
        required=True,
        maxlength=64,
    )
)

Initialization

Initialize an HTML component.

Parameters:
  • element – The HTML element tag name (e.g., textarea, input, button). Can be None, but make sure element is returned by get_element method.

  • accept_inner_html – Whether the HTML component accepts an inner body (e.g., inner-body-here).

  • inner_html – Inner html to add to the HTML component. Defaults to None.

  • properties – Dictionary for properties to initialize the component with.

  • props – Just same as properties argument (added for simplicity).

  • style – Dictionary for style to initialize the component with.

  • **kwargs – Extra keyword arguments

Raises:

HtmlComponentError – If ‘element’ is not a string or ‘inner_html’ is set but ‘accept_inner_html’ is False.

on_create()[source]