Skip to content

Adding attributes to inputs #1730

@thohan88

Description

@thohan88

There may be an easy way of doing this, but all my attempts to add attributes to an input using input_xxx() has failed.

My use case is adding bootstrap validation by setting the required attribute. It would be nice if something like this could work:

ui.input_text("id", "label", {"required":True})
# TypeError: Invalid type for attribute: <class 'dict'>.

I guess it would not be clear whether such attributes applies to the <form>, <label> or <input> tag, so I'm not really sure what a good api looks like here. This is an okay workaround for simple inputs, but more cumbersome for complex inputs (e.g input_select).

ui.tags.input(
  id = "id", 
  label = "label",
  type = "text",
  required = True
).get_html_string
# <input id="id" label="label" type="text" required=""/>

I also believe this workaround requires you to use resolve_id(id) manually to make it work in modules?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions