Skip to content

Commit 4d75567

Browse files
committed
add layout
1 parent c1a8d0e commit 4d75567

9 files changed

Lines changed: 34 additions & 17 deletions

File tree

apps/app-mobile/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@form-example/app-mobile",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"private": true,
55
"type": "module",
66
"scripts": {

apps/app-mobile/src/pages/home.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import {createFormInstance, FormView} from "@coding-form/form-engine";
21
import type {FormMeta} from "@coding-form/form-engine";
2+
import {createFormInstance, FormInstance, FormView} from "@coding-form/form-engine";
33
import {Button, Space} from "antd-mobile";
4-
import {FormInstance} from "@coding-form/form-engine";
54

65
const HomePage = () => {
76

@@ -30,11 +29,14 @@ const HomePage = () => {
3029
<FormView
3130
meta={meta}
3231
form={form}
32+
onValuesChange={(partial, values, formCode) => {
33+
console.log(partial, values, formCode);
34+
}}
3335
validators={[
3436
{
35-
target:'name',
36-
validator:(_instance:FormInstance,value:any)=>{
37-
if(value){
37+
target: 'name',
38+
validator: (_instance: FormInstance, value: any) => {
39+
if (value) {
3840
return true;
3941
}
4042
return '你可真行'
@@ -67,25 +69,25 @@ const HomePage = () => {
6769

6870
<Button
6971
onClick={() => {
70-
form.hiddenFields(true,['name']);
72+
form.hiddenFields(true, ['name']);
7173
}}
7274
>enable hidden</Button>
7375

7476
<Button
7577
onClick={() => {
76-
form.hiddenFields(false,['name']);
78+
form.hiddenFields(false, ['name']);
7779
}}
7880
>disable hidden</Button>
7981

8082
<Button
8183
onClick={() => {
82-
form.requiredFields(true,['name']);
84+
form.requiredFields(true, ['name']);
8385
}}
8486
>enable required</Button>
8587

8688
<Button
8789
onClick={() => {
88-
form.requiredFields(false,['name']);
90+
form.requiredFields(false, ['name']);
8991
}}
9092
>disable required</Button>
9193
</Space>

apps/app-pc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@form-example/app-pc",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"private": true,
55
"type": "module",
66
"scripts": {

apps/app-pc/src/pages/home.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const HomePage = () => {
5151
onFinish={(values, formCode)=>{
5252
console.log(values, formCode);
5353
}}
54+
onValuesChange={(partial, values, formCode) => {
55+
console.log(partial, values, formCode);
56+
}}
5457
validators={[
5558
{
5659
target:'name',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coding-form/root",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"description": "form-engine",
55
"main": "index.js",
66
"scripts": {

packages/form-engine/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coding-form/form-engine",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"description": "form-engine components",
55
"keywords": [
66
"coding-form",

packages/form-engine/src/form/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export const FormViewContent: React.FC<FormViewContentProps> = (props) => {
3636
props.onBlur?.(formCode);
3737
}
3838

39+
const handleOnValuesChange = (partial:any,values:any,formCode:string) => {
40+
props.onValuesChange?.(partial,values,formCode);
41+
}
42+
3943
return (
4044
<FormContext.Provider value={context}>
4145
{props.header}
@@ -47,6 +51,7 @@ export const FormViewContent: React.FC<FormViewContentProps> = (props) => {
4751
onBlur={handleOnBlur}
4852
children={props.children}
4953
layout={props.layout}
54+
onValuesChange={handleOnValuesChange}
5055
/>
5156
{subFormList && subFormList.map(item=>{
5257
return (
@@ -57,6 +62,7 @@ export const FormViewContent: React.FC<FormViewContentProps> = (props) => {
5762
onFinish={handleOnFinish}
5863
onBlur={handleOnBlur}
5964
layout={props.layout}
65+
onValuesChange={handleOnValuesChange}
6066
/>
6167
)
6268
})}

packages/form-engine/src/form/sub-view.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ interface FormSubViewProps {
55
formCode: string;
66
Form: React.ComponentType<any>;
77
review: boolean;
8-
onFinish: (values:any,formCode:string) => void;
9-
onBlur: (formCode:string) => void;
8+
onFinish?: (values:any,formCode:string) => void;
9+
onValuesChange?:(partial:any,values:any,formCode:string)=>void;
10+
onBlur?: (formCode:string) => void;
1011
children?:React.ReactNode;
1112
layout?:'horizontal' | 'vertical';
1213
}
@@ -56,10 +57,13 @@ export const FormSubView: React.FC<FormSubViewProps> = (props) => {
5657
form={formTarget}
5758
layout={props.layout}
5859
onBlur={()=>{
59-
props.onBlur(props.formCode);
60+
props.onBlur?.(props.formCode);
6061
}}
6162
onFinish={(values:any)=>{
62-
props.onFinish(values,props.formCode);
63+
props.onFinish?.(values,props.formCode);
64+
}}
65+
onValuesChange={(partial:any,values:any)=>{
66+
props.onValuesChange?.(partial,values,props.formCode);
6367
}}
6468
>
6569
{props.children}

packages/form-engine/src/types/view.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export interface FormViewProps {
9898
form?: FormInstance;
9999
/** 布局方向 **/
100100
layout?:'horizontal' | 'vertical';
101+
/** 表单值更新事件 **/
102+
onValuesChange?:(partial:any,values:any,formCode?:string)=>void;
101103
/** 表单提交数据 **/
102104
onFinish?: (values:any,formCode?:string) => void;
103105
/** 表单失去焦点事件 **/

0 commit comments

Comments
 (0)