feat: 更新 formkit 配置,优化组件导入和调试信息,调整提交延迟
This commit is contained in:
@ -2,7 +2,7 @@ export function debugPlugin(node: import('@formkit/core').FormKitNode) {
|
|||||||
if (['button', 'submit', 'hidden', 'group', 'list', 'meta'].includes(node.props.type)) return;
|
if (['button', 'submit', 'hidden', 'group', 'list', 'meta'].includes(node.props.type)) return;
|
||||||
|
|
||||||
node.on('created', () => {
|
node.on('created', () => {
|
||||||
console.group('[node created]', node.props.label || node.props.submitLabel);
|
console.group('[node created]', node.props.label || node.props.submitLabel || node.name);
|
||||||
console.debug(`node :>> `, node);
|
console.debug(`node :>> `, node);
|
||||||
console.debug(`node.props.definition :>> `, node.props.definition);
|
console.debug(`node.props.definition :>> `, node.props.definition);
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import { form } from '@/__fk-inputs__/inputs/form';
|
||||||
|
import { PInputPassword } from '@/__fk-inputs__/inputs/input-password';
|
||||||
|
import { PInputText } from '@/__fk-inputs__/inputs/input-text';
|
||||||
import { createAutoAnimatePlugin, createAutoHeightTextareaPlugin } from '@formkit/addons';
|
import { createAutoAnimatePlugin, createAutoHeightTextareaPlugin } from '@formkit/addons';
|
||||||
import { autoAnimatePlugin } from '@formkit/auto-animate/vue';
|
import { autoAnimatePlugin } from '@formkit/auto-animate/vue';
|
||||||
import type { FormKitOptions } from '@formkit/core';
|
import type { FormKitOptions } from '@formkit/core';
|
||||||
@ -10,9 +13,6 @@ import { /* defaultConfig, */ bindings, plugin /* defaultConfig */ } from '@form
|
|||||||
import type { App } from 'vue';
|
import type { App } from 'vue';
|
||||||
import { addAsteriskPlugin } from './formkit.config.plugin.addAsteriskPlugin';
|
import { addAsteriskPlugin } from './formkit.config.plugin.addAsteriskPlugin';
|
||||||
import { debugPlugin } from './formkit.config.plugin.debug';
|
import { debugPlugin } from './formkit.config.plugin.debug';
|
||||||
import { form } from '@/__fk-inputs__/inputs/form';
|
|
||||||
import { PInputText } from '@/__fk-inputs__/inputs/input-text';
|
|
||||||
import { PInputPassword } from '@/__fk-inputs__/inputs/input-password';
|
|
||||||
|
|
||||||
// const apiKey = 'fk-6cdd5192223'
|
// const apiKey = 'fk-6cdd5192223'
|
||||||
const config: FormKitOptions = {
|
const config: FormKitOptions = {
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
import { FormKitTypeDefinition } from '@formkit/core'
|
import { FormKitTypeDefinition } from '@formkit/core';
|
||||||
import {
|
import { actions, submitInput, forms, disablesChildren, createSection } from '@formkit/inputs';
|
||||||
actions,
|
import { messages } from '../sections/messages';
|
||||||
submitInput,
|
import PButton from 'primevue/button';
|
||||||
forms,
|
import { markRaw } from 'vue';
|
||||||
disablesChildren,
|
|
||||||
createSection,
|
|
||||||
} from '@formkit/inputs'
|
|
||||||
import { messages } from '../sections/messages'
|
|
||||||
|
|
||||||
const formInput = createSection('form', () => ({
|
const formInput = createSection('form', () => ({
|
||||||
$el: 'form',
|
$el: 'form',
|
||||||
@ -20,42 +16,29 @@ const formInput = createSection('form', () => ({
|
|||||||
onSubmit: '$handlers.submit',
|
onSubmit: '$handlers.submit',
|
||||||
'data-loading': '$state.loading || undefined',
|
'data-loading': '$state.loading || undefined',
|
||||||
},
|
},
|
||||||
}))
|
}));
|
||||||
|
|
||||||
/**
|
|
||||||
* Input definition for a form.
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export const form: FormKitTypeDefinition = {
|
export const form: FormKitTypeDefinition = {
|
||||||
/**
|
|
||||||
* The actual schema of the input, or a function that returns the schema.
|
|
||||||
*/
|
|
||||||
schema: formInput(
|
schema: formInput(
|
||||||
'$slots.default',
|
'$slots.default',
|
||||||
messages(),
|
messages(),
|
||||||
actions(submitInput())
|
actions(submitInput()),
|
||||||
|
createSection('button', () => ({
|
||||||
|
$cmp: markRaw(PButton) as any,
|
||||||
|
bind: '$submitAttrs',
|
||||||
|
props: {
|
||||||
|
type: 'submit',
|
||||||
|
label: '$submitLabel',
|
||||||
|
},
|
||||||
|
}))(),
|
||||||
),
|
),
|
||||||
/**
|
|
||||||
* The type of node, can be a list, group, or input.
|
|
||||||
*/
|
|
||||||
type: 'group',
|
type: 'group',
|
||||||
/**
|
|
||||||
* An array of extra props to accept for this input.
|
|
||||||
*/
|
|
||||||
props: [
|
props: [
|
||||||
'actions',
|
|
||||||
'submit',
|
|
||||||
'submitLabel',
|
'submitLabel',
|
||||||
'submitAttrs',
|
'submitAttrs',
|
||||||
'submitBehavior',
|
'submitBehavior',
|
||||||
'incompleteMessage',
|
'incompleteMessage', // 抱歉,部分字段未被正确填写。
|
||||||
],
|
],
|
||||||
/**
|
|
||||||
* Additional features that should be added to your input
|
|
||||||
*/
|
|
||||||
features: [forms, disablesChildren],
|
features: [forms, disablesChildren],
|
||||||
/**
|
|
||||||
* The key used to memoize the schema.
|
|
||||||
*/
|
|
||||||
// schemaMemoKey: 'rorzq1rsrf',
|
// schemaMemoKey: 'rorzq1rsrf',
|
||||||
}
|
};
|
||||||
|
@ -4,6 +4,6 @@ import { markRaw } from 'vue';
|
|||||||
|
|
||||||
export const messages = createSection('messages', () => ({
|
export const messages = createSection('messages', () => ({
|
||||||
$cmp: markRaw(MessagesCmp) as any, // [element = node.$cmp](https://github.com/formkit/formkit/blob/2d5387ba98597775cb2a752af65aee84bc438863/packages/vue/src/FormKitSchema.ts#L449)
|
$cmp: markRaw(MessagesCmp) as any, // [element = node.$cmp](https://github.com/formkit/formkit/blob/2d5387ba98597775cb2a752af65aee84bc438863/packages/vue/src/FormKitSchema.ts#L449)
|
||||||
props: { context: '$node.context', },
|
props: { context: '$node.context' },
|
||||||
if: '$defaultMessagePlacement && $fns.length($messages)',
|
if: '$defaultMessagePlacement && $fns.length($messages)',
|
||||||
}))
|
}));
|
||||||
|
@ -3,13 +3,15 @@ import { text } from '@/__fk-inputs__/inputs/_demo_text';
|
|||||||
import { FormKitNode } from '@formkit/core';
|
import { FormKitNode } from '@formkit/core';
|
||||||
import Swal from 'sweetalert2';
|
import Swal from 'sweetalert2';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function submit(formData: Record<string, any>, formNode: FormKitNode) {
|
async function submit(formData: Record<string, any>, formNode: FormKitNode) {
|
||||||
console.group('submit');
|
console.group('submit');
|
||||||
console.log('formData :>> ', formData);
|
console.log('formData :>> ', formData);
|
||||||
console.log('formNode :>> ', formNode);
|
console.log('formNode :>> ', formNode);
|
||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
|
|
||||||
await new Promise(r => setTimeout(r, 500))
|
await new Promise(r => setTimeout(r, 2000))
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: 'Submitted! 🎉',
|
title: 'Submitted! 🎉',
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
@ -40,9 +42,9 @@ async function submit(formData: Record<string, any>, formNode: FormKitNode) {
|
|||||||
#default="{ value }"
|
#default="{ value }"
|
||||||
@submit="submit"
|
@submit="submit"
|
||||||
submit-label="提交 ✨"
|
submit-label="提交 ✨"
|
||||||
:submit-attrs="{ class: 'btn btn-primary' }"
|
:submit-attrs="{
|
||||||
:errors="['our server is not working.', 'But we don’t like you anyway!']"
|
'some-submit-attr': 'value',
|
||||||
incomplete-message="Please fill out all fields."
|
}"
|
||||||
>
|
>
|
||||||
<FormKit
|
<FormKit
|
||||||
type="PInputText"
|
type="PInputText"
|
||||||
@ -65,31 +67,28 @@ async function submit(formData: Record<string, any>, formNode: FormKitNode) {
|
|||||||
:feedback="false"
|
:feedback="false"
|
||||||
/>
|
/>
|
||||||
<FormKit
|
<FormKit
|
||||||
|
v-if="!value?.PInputPassword"
|
||||||
:type="text"
|
:type="text"
|
||||||
label="customType"
|
:preserve="false"
|
||||||
validation="required"
|
name="customType"
|
||||||
validation-visibility="live"
|
value="this input will display if the password is empty"
|
||||||
>
|
>
|
||||||
<!-- <template #label>
|
<!-- <template #label>
|
||||||
<div>labelll</div>
|
<div>labelll</div>
|
||||||
</template> -->
|
</template> -->
|
||||||
</FormKit>
|
</FormKit>
|
||||||
|
|
||||||
<FormKit
|
<!-- <FormKit
|
||||||
|
v-if="false"
|
||||||
type="text"
|
type="text"
|
||||||
label="默认text"
|
label="默认text"
|
||||||
validation="required"
|
validation="required"
|
||||||
>
|
>
|
||||||
</FormKit>
|
</FormKit> -->
|
||||||
|
|
||||||
<pre class="font-mono text-sm p-4 bg-slate-100 mb-4 dark:bg-gray-900 overflow-x-auto rounded-md shadow-inner dark:text-gray-300
|
<pre class="font-mono text-sm p-4 bg-slate-100 dark:bg-gray-900 overflow-x-auto rounded-md shadow-inner dark:text-gray-300
|
||||||
">{{ value }}</pre>
|
">{{ value }}</pre>
|
||||||
<!-- <FormKitSummary /> -->
|
<!-- <FormKitSummary /> -->
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="btn btn-primary"
|
|
||||||
>提交 ✨ </button>
|
|
||||||
</FormKit>
|
</FormKit>
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user