From c57f5570d1d2ba3fd26757ab80e6d5fea69f63fc Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Tue, 28 Nov 2023 22:52:03 +0000 Subject: [PATCH] cleanup inline forms --- packages/fastui/src/components/form.tsx | 8 +++----- python/demo/tables.py | 6 ------ python/fastui/json_schema.py | 1 + 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/fastui/src/components/form.tsx b/packages/fastui/src/components/form.tsx index e7bbd7bb..d037efd0 100644 --- a/packages/fastui/src/components/form.tsx +++ b/packages/fastui/src/components/form.tsx @@ -55,15 +55,13 @@ export const FormComp: FC = (props) => { if (method === 'GOTO') { // this seems to work in common cases, but typescript doesn't like it const query = new URLSearchParams(formData as any) - console.log(Object.fromEntries(query.entries())) for (const [k, v] of query.entries()) { - console.log(k, v) if (v === '') { query.delete(k) } } const queryStr = query.toString() - goto(queryStr === '' ? submitUrl : `${submitUrl}?${query}`) + goto(queryStr === '' ? submitUrl : `${submitUrl}?${queryStr}`) setLocked(false) return } @@ -106,8 +104,8 @@ export const FormComp: FC = (props) => { } const onChange = useCallback(() => { - if (submitOnChange) { - const formData = new FormData(formRef.current!) + if (submitOnChange && formRef.current) { + const formData = new FormData(formRef.current) submit(formData) } }, [submitOnChange, submit]) diff --git a/python/demo/tables.py b/python/demo/tables.py index 3e61bc09..85dc768a 100644 --- a/python/demo/tables.py +++ b/python/demo/tables.py @@ -8,7 +8,6 @@ from fastui import components as c from fastui.components.display import DisplayLookup, DisplayMode from fastui.events import BackEvent, GoToEvent -from fastui.forms import FormResponse from pydantic import BaseModel, Field, TypeAdapter from .shared import navbar @@ -107,11 +106,6 @@ def cities_view(page: int = 1, country: str | None = None) -> list[AnyComponent] ] -@router.get('/cities/query', response_model=FormResponse, response_model_exclude_none=True) -def cities_view(country: str) -> FormResponse: - return FormResponse(event=GoToEvent(url=f'/table/cities?country={country}')) - - @router.get('/cities/{city_id}', response_model=FastUI, response_model_exclude_none=True) def city_view(city_id: int) -> list[AnyComponent]: city = cities_lookup()[city_id] diff --git a/python/fastui/json_schema.py b/python/fastui/json_schema.py index d67a246e..85a64cf3 100644 --- a/python/fastui/json_schema.py +++ b/python/fastui/json_schema.py @@ -225,6 +225,7 @@ def special_string_field( return FormFieldSelect( name=name, title=title, + placeholder=schema.get('placeholder'), required=required, multiple=multiple, options=[SelectOption(value=v, label=enum_labels.get(v) or as_title(v)) for v in enum],