Add input type 'search' to textbox

Can the input type ‘search’ be added to the list of options for the TextBox config?
This allows browsers to render an “x” clear icon automatically for that field - it would really help mobile users that need to clear the long text quickly inside a text box.

Since this type=‘search’ behaves just like type=‘text’, no additional work would be needed.

Here’s the relevant doc:

Thank you!

2 Likes

Anvil does not support that by default but you can use this simple piece of code to achieve that

from anvil.js import get_dom_node

get_dom_node(self.text_box).type='search'

I think you can just do

self.text_box.type = "search"

It’s just not a supported option in the designer.

3 Likes

I wish I had known it!

I have created my own custom component with a little button with the x :upside_down_face:

Thank you folks!

I just tried both suggestions - self.text_box.type=“search” does not generate an error, but the source of the page still shows type=“text”. If you use the other suggestion to go through js - the type changes to “search”. However, the “x” does not appear in the field. Probably styling? - will need to test this further.