I can bind select
This commit is contained in:
0
src/myfasthtml/examples/__init__.py
Normal file
0
src/myfasthtml/examples/__init__.py
Normal file
51
src/myfasthtml/examples/binding_checkbox.py
Normal file
51
src/myfasthtml/examples/binding_checkbox.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
from fasthtml import serve
|
||||
from fasthtml.components import *
|
||||
|
||||
from myfasthtml.controls.helpers import mk
|
||||
from myfasthtml.core.bindings import Binding, BooleanConverter
|
||||
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: str = "Hello World"
|
||||
checked: bool = False
|
||||
|
||||
|
||||
data = Data()
|
||||
|
||||
|
||||
@rt("/set_checkbox")
|
||||
def post(check_box_name: str = None):
|
||||
print(check_box_name)
|
||||
|
||||
|
||||
@rt("/")
|
||||
def index():
|
||||
return Div(
|
||||
mk.mk(Input(name="checked_name", type="checkbox"), binding=Binding(data, attr="checked")),
|
||||
mk.mk(Label("Text"), binding=Binding(data, attr="checked", converter=BooleanConverter())),
|
||||
)
|
||||
|
||||
|
||||
@rt("/test_checkbox_htmx")
|
||||
def get():
|
||||
check_box = Input(type="checkbox", name="check_box_name", hx_post="/set_checkbox")
|
||||
return check_box
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
debug_routes(app)
|
||||
serve(port=5002)
|
||||
33
src/myfasthtml/examples/binding_input.py
Normal file
33
src/myfasthtml/examples/binding_input.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
|
||||
app, rt = create_app(protect_routes=False)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Data:
|
||||
value: Any = "Hello World"
|
||||
|
||||
|
||||
data = Data()
|
||||
|
||||
|
||||
@rt("/")
|
||||
def get():
|
||||
return Div(
|
||||
mk.mk(Input(name="input_name"), binding=Binding(data, attr="value").htmx(trigger="input changed")),
|
||||
mk.mk(Label("Text"), binding=Binding(data, attr="value"))
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
debug_routes(app)
|
||||
serve(port=5002)
|
||||
47
src/myfasthtml/examples/binding_radio.py
Normal file
47
src/myfasthtml/examples/binding_radio.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
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: str = "Hello World"
|
||||
checked: bool = False
|
||||
|
||||
|
||||
data = Data()
|
||||
|
||||
|
||||
@rt("/")
|
||||
def get():
|
||||
radio1 = Input(type="radio", name="radio_name", value="option1")
|
||||
radio2 = Input(type="radio", name="radio_name", value="option2", checked=True)
|
||||
radio3 = Input(type="radio", name="radio_name", value="option3")
|
||||
label_elt = Label("hi hi hi !")
|
||||
|
||||
mk.manage_binding(radio1, Binding(data))
|
||||
mk.manage_binding(radio2, Binding(data))
|
||||
mk.manage_binding(radio3, Binding(data))
|
||||
mk.manage_binding(label_elt, Binding(data))
|
||||
|
||||
return radio1, radio2, radio3, label_elt
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
debug_routes(app)
|
||||
serve(port=5002)
|
||||
46
src/myfasthtml/examples/binding_select.py
Normal file
46
src/myfasthtml/examples/binding_select.py
Normal file
@@ -0,0 +1,46 @@
|
||||
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"
|
||||
)
|
||||
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)
|
||||
33
src/myfasthtml/examples/binding_textarea.py
Normal file
33
src/myfasthtml/examples/binding_textarea.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
|
||||
app, rt = create_app(protect_routes=False)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Data:
|
||||
value: Any = "Hello World"
|
||||
|
||||
|
||||
data = Data()
|
||||
|
||||
|
||||
@rt("/")
|
||||
def get():
|
||||
return Div(
|
||||
mk.mk(Textarea(name="input_name"), binding=Binding(data, attr="value").htmx(trigger="input changed")),
|
||||
mk.mk(Label("Text"), binding=Binding(data, attr="value"))
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
debug_routes(app)
|
||||
serve(port=5002)
|
||||
26
src/myfasthtml/examples/clickme.py
Normal file
26
src/myfasthtml/examples/clickme.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from fasthtml import serve
|
||||
|
||||
from myfasthtml.controls.helpers import mk
|
||||
from myfasthtml.core.commands import Command
|
||||
from myfasthtml.myfastapp import create_app
|
||||
|
||||
|
||||
# Define a simple command action
|
||||
def say_hello():
|
||||
return "Hello, FastHtml!"
|
||||
|
||||
|
||||
# Create the command
|
||||
hello_command = Command("say_hello", "Responds with a greeting", say_hello)
|
||||
|
||||
# Create the app
|
||||
app, rt = create_app(protect_routes=False)
|
||||
|
||||
|
||||
@rt("/")
|
||||
def get_homepage():
|
||||
return mk.button("Click Me!", command=hello_command)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
serve(port=5002)
|
||||
25
src/myfasthtml/examples/command_with_htmx_params.py
Normal file
25
src/myfasthtml/examples/command_with_htmx_params.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from fasthtml import serve
|
||||
from fasthtml.components import *
|
||||
|
||||
from myfasthtml.controls.helpers import mk
|
||||
from myfasthtml.core.commands import Command
|
||||
from myfasthtml.icons.fa import icon_home
|
||||
from myfasthtml.myfastapp import create_app
|
||||
|
||||
app, rt = create_app(protect_routes=False)
|
||||
|
||||
|
||||
def change_text():
|
||||
return "New text"
|
||||
|
||||
|
||||
command = Command("change_text", "change the text", change_text).htmx(target="#text")
|
||||
|
||||
|
||||
@rt("/")
|
||||
def index():
|
||||
return mk.button(Div(mk.icon(icon_home), Div("Hello World", id="text"), cls="flex"), command=command)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
serve(port=5002)
|
||||
15
src/myfasthtml/examples/helloworld.py
Normal file
15
src/myfasthtml/examples/helloworld.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from fasthtml import serve
|
||||
from fasthtml.components import *
|
||||
|
||||
from myfasthtml.myfastapp import create_app
|
||||
|
||||
app, rt = create_app(protect_routes=False)
|
||||
|
||||
|
||||
@rt("/")
|
||||
def get_homepage():
|
||||
return Div("Hello, FastHtml!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
serve(port=5002)
|
||||
Reference in New Issue
Block a user