Skip to main content

Custom Widget

Allows for a fully customizable widget with custom HTML, CSS, and JS.

Examples

Basic Example

The following example shows how to create a custom widget with a button that returns the current date.

from abstra.forms import read_custom

current_date = read_custom(
"<button id='date-btn'>Get current date</button>",
label="Custom Widget",
js="""
document.getElementById('date-btn').addEventListener('click',function() {
const date = new Date();
const day = date.getDate();
const month = date.getMonth() + 1;
const year = date.getFullYear();

changeEvent(day + '/' + month + '/' + year);
});
""",
css="""
body {
margin: 0;
padding: 0;
}

#date-btn {
cursor: pointer;
background-color: #343b46;
border: none;
border-radius: 4px;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}

#date-btn:hover {
background-color: #3e4756;
}
""",
)

Parameters

NameDescriptionType
html_bodyThe HTML body contentstr
initial_valueThe initial value to be stored in custom widget state.Any
labelThe label to display to the userstr
html_headThe HTML head contentstr
cssThe widget's CSSstr
jsThe widget's JavaScriptstr
heightThe widget's heightint
full_widthWhether the input should use full screen width. Defaults to False.bool
button_textWhat text to display on the button when the widget is not part of a Page. Defaults to 'Next'.str

Return Values

TypeDescription
AnyThe custom response