Forms: enable Save while typing and keep the action bar buttons in place

This commit is contained in:
Stalwart Git Sync committed 2026-12-01 11:06:15 +01:00
1 parent 6e76d2f9e9
commit cb0af4334f
2 files changed
+20 -4

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. This projec
### Fixed
- Browser auto-translation (Chrome, Edge, Safari) is turned off for the web interface, which crashed with a `removeChild` error when the translator rewrote the page.
- Forms: Save is enabled as soon as a field is edited, without leaving the field first, and the Delete, Cancel and Save buttons no longer move when the "Unsaved changes" label appears.
## [2.1.2] - 2026-11-29
+19 -4
View File
@@ -155,6 +155,7 @@ export function DynamicForm({
const model = useDynamicForm(viewName, objectId, { accountId, fieldOverrides, createValues, showCreatedValues });
const { schema, resolved, mode, isSingleton, state, isDirty, saving, loading, loadError } = model;
const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
const [pendingInput, setPendingInput] = useState(false);
const title = useFormTitle(model);
const sectionPrefix = useId();
const wide = useSyncExternalStore(subscribeWide, isWide, () => false);
@@ -165,6 +166,7 @@ export function DynamicForm({
const isCreate = mode === 'create';
const readOnly = !isCreate && !canUpdate;
const canDelete = !isCreate && !isSingleton && canDestroy;
const hasChanges = isDirty || pendingInput;
const subtitle = (model.parentForm ?? model.variantForm)?.subtitle;
const errorText = state.generalError ?? loadError;
const header = (
@@ -222,7 +224,15 @@ export function DynamicForm({
<div className={cn(showIndex && 'xl:grid xl:grid-cols-[11rem_minmax(0,1fr)] xl:items-start xl:gap-6')}>
{showIndex && wide && <SectionIndex sections={model.sections} sectionId={sectionId} />}
<div className="space-y-3.5">
<div
className="space-y-3.5"
onInput={(e) => {
if (!pendingInput && e.target instanceof Node && e.currentTarget.contains(e.target)) setPendingInput(true);
}}
onBlur={() => {
if (pendingInput) setPendingInput(false);
}}
>
<FormProvider
schema={schema}
mode={mode}
@@ -266,8 +276,13 @@ export function DynamicForm({
<FloatingActionDivider />
</>
)}
{isDirty && (
<span className="flex items-center gap-2 px-2 text-[13px] text-ink-muted max-sm:hidden">
{!readOnly && (
<span
className={cn(
'flex items-center gap-2 px-2 text-[13px] text-ink-muted max-sm:hidden',
!hasChanges && 'invisible',
)}
>
<FloatingActionDot />
{t('form.unsavedChangesLabel', 'Unsaved changes')}
</span>
@@ -281,7 +296,7 @@ export function DynamicForm({
size="sm"
className="shadow-none"
onClick={() => void model.save()}
disabled={saving || (!isCreate && !isDirty)}
disabled={saving || (!isCreate && !hasChanges)}
>
{saving ? (
<Loader2 className="h-4 w-4 animate-spin" aria-hidden="true" />