Skip to content

Commit

Permalink
cleanup inline forms
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Nov 28, 2023
1 parent dc7461b commit c57f557
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
8 changes: 3 additions & 5 deletions packages/fastui/src/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ export const FormComp: FC<FormProps | ModelFormProps> = (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
}
Expand Down Expand Up @@ -106,8 +104,8 @@ export const FormComp: FC<FormProps | ModelFormProps> = (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])
Expand Down
6 changes: 0 additions & 6 deletions python/demo/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions python/fastui/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit c57f557

Please sign in to comment.