Skip to content

Commit

Permalink
feat: Delay validation on form modal. (#225)
Browse files Browse the repository at this point in the history
Since the forms are short on the modals delay the validation until the user tries to submit the form.
  • Loading branch information
Zoramite committed Aug 12, 2021
1 parent 4a5e008 commit 92fc14a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/ts/editor/ui/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {ListenersMixin} from '../../mixin/listeners';
import {UuidMixin} from '@blinkk/selective-edit/dist/mixins/uuid';
import {LiveEditorSelectiveEditorConfig, cloneSelectiveConfig} from '../editor';
import {templateApiError} from './error';
import merge from 'lodash.merge';

/**
* Priority of the modal.
Expand Down Expand Up @@ -359,13 +360,22 @@ export class FormDialogModal extends DialogModal {
this.config = config;
this.data = new DeepObject({});

// Clone to prevent shared values if editor changes config.
this.selective = new SelectiveEditor(
const selectiveConfig = merge(
{},
// Clone to prevent shared values if editor changes config.
cloneSelectiveConfig(
this.config.selectiveConfig as LiveEditorSelectiveEditorConfig
)
),
{
// For smaller forms, like in modals, delay the validation
// until after the form has been submitted.
delayValidation: true,
}
);

// Clone to prevent shared values if editor changes config.
this.selective = new SelectiveEditor(selectiveConfig);

// When the project type is updated the selective editor changes.
this.config.state.addListener(
StatePromiseKeys.SetProjectType,
Expand Down
2 changes: 1 addition & 1 deletion src/ts/editor/ui/parts/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {
repeat,
} from '@blinkk/selective-edit';
import {DialogActionLevel, FormDialogModal} from '../modal';
import {EVENT_RENDER_COMPLETE, EVENT_WORKSPACE_LOAD} from '../../events';
import {
LiveEditorSelectiveEditorConfig,
cloneSelectiveConfig,
} from '../../editor';
import {exampleIcon, githubIcon, localIcon} from '../icons';

import {EVENT_RENDER_COMPLETE, EVENT_WORKSPACE_LOAD} from '../../events';
import {EditorState} from '../../state';
import {FieldConfig} from '@blinkk/selective-edit/dist/selective/field';
import {NotificationAction} from './notifications';
Expand Down

0 comments on commit 92fc14a

Please sign in to comment.