I can bind multi-select
This commit is contained in:
47
src/myfasthtml/examples/binding_select_multiple.py
Normal file
47
src/myfasthtml/examples/binding_select_multiple.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from fasthtml import serve
|
||||
from fasthtml.components import *
|
||||
|
||||
from myfasthtml.controls.helpers import mk
|
||||
from myfasthtml.core.bindings import Binding
|
||||
from myfasthtml.core.utils import debug_routes
|
||||
from myfasthtml.myfastapp import create_app
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG, # Set logging level to DEBUG
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', # Log format
|
||||
datefmt='%Y-%m-%d %H:%M:%S', # Timestamp format
|
||||
)
|
||||
|
||||
app, rt = create_app(protect_routes=False)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Data:
|
||||
value: Any = "Hello World"
|
||||
|
||||
|
||||
data = Data()
|
||||
|
||||
|
||||
@rt("/")
|
||||
def get():
|
||||
select_elt = Select(
|
||||
Option("Option 1", value="option1"),
|
||||
Option("Option 2", value="option2"),
|
||||
Option("Option 3", value="option3"),
|
||||
name="select_name",
|
||||
multiple=True
|
||||
)
|
||||
label_elt = Label()
|
||||
mk.manage_binding(select_elt, Binding(data), init_binding=False)
|
||||
mk.manage_binding(label_elt, Binding(data))
|
||||
return select_elt, label_elt
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
debug_routes(app)
|
||||
serve(port=5002)
|
||||
Reference in New Issue
Block a user