Skip to content

Commit bf2c016

Browse files
committed
remove event context
1 parent c6a2387 commit bf2c016

33 files changed

Lines changed: 476 additions & 319 deletions

File tree

apps/app-mobile/src/components/string/index.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import {Form, Input} from "antd-mobile";
22
import React from "react";
3-
import {useFormContext,type FormItemProps} from "@coding-form/form-view";
3+
import {type FormItemProps} from "@coding-form/form-view";
44

55
export const FormString: React.FC<FormItemProps> = (props) => {
66

7-
const context = useFormContext();
8-
9-
const rules = context.validate.getValidatorRules(props.code);
10-
117
return (
128
<Form.Item
13-
name={props.code}
14-
key={props.code}
15-
label={props.name}
9+
name={props.name}
10+
key={props.name}
11+
label={props.label}
1612
required={props.required}
1713
hidden={props.hidden}
18-
rules={rules}
14+
rules={props.rules}
1915
>
20-
<Input placeholder={props.placeholder}/>
16+
<Input
17+
placeholder={props.placeholder}
18+
onChange={(event)=>{
19+
props.onChange?.(event);
20+
}}
21+
/>
2122
</Form.Item>
2223
)
2324

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createFormInstance, FormView} from "@coding-form/form-view";
2-
import type {FormMeta} from "@coding-form/form-types";
2+
import type {FormMeta} from "@coding-form/form-view";
33
import {Button, Space} from "antd-mobile";
44

55
const HomePage = () => {
@@ -22,7 +22,7 @@ const HomePage = () => {
2222
subForms: []
2323
}
2424

25-
const form = createFormInstance();
25+
const form = createFormInstance(meta);
2626

2727
return (
2828
<div>
@@ -31,7 +31,7 @@ const HomePage = () => {
3131
form={form}
3232
validators={[
3333
{
34-
fieldCode:'name',
34+
target:'name',
3535
validator:(value,instance)=>{
3636
if(value){
3737
return true;

apps/app-pc/src/components/string/index.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import {Form, Input} from "antd";
22
import React from "react";
3-
import {useFormContext,type FormItemProps} from "@coding-form/form-view";
3+
import {type FormItemProps} from "@coding-form/form-view";
44

55
export const FormString: React.FC<FormItemProps> = (props) => {
66

7-
const context = useFormContext();
8-
9-
const rules = context.validate.getValidatorRules(props.code);
10-
117
return (
128
<Form.Item
13-
name={props.code}
14-
key={props.code}
15-
label={props.name}
9+
name={props.name}
10+
key={props.name}
11+
label={props.label}
1612
required={props.required}
1713
hidden={props.hidden}
18-
rules={rules}
14+
rules={props.rules}
1915
>
20-
<Input placeholder={props.placeholder}/>
16+
<Input
17+
placeholder={props.placeholder}
18+
onChange={(event)=>{
19+
props.onChange?.(event.target.value);
20+
}}
21+
/>
2122
</Form.Item>
2223
)
2324

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {createFormInstance, FormView} from "@coding-form/form-view";
2-
import type {FormMeta} from "@coding-form/form-types";
2+
import type {FormMeta} from "@coding-form/form-view";
33
import {Button, Space} from "antd";
4+
import type {OnChangeEvent} from "@coding-form/form-view";
45

56
const HomePage = () => {
67

@@ -21,7 +22,7 @@ const HomePage = () => {
2122
subForms: []
2223
}
2324

24-
const form = createFormInstance();
25+
const form = createFormInstance(meta);
2526

2627
return (
2728
<div>
@@ -30,7 +31,7 @@ const HomePage = () => {
3031
form={form}
3132
validators={[
3233
{
33-
fieldCode:'name',
34+
target:'name',
3435
validator:(value,instance)=>{
3536
if(value){
3637
return true;
@@ -39,6 +40,14 @@ const HomePage = () => {
3940
}
4041
}
4142
]}
43+
events={[
44+
{
45+
target:'name',
46+
event:(value)=>{
47+
console.log('value',value)
48+
}
49+
} as OnChangeEvent
50+
]}
4251
/>
4352

4453
<Space>

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build:form-types": "pnpm -F @coding-form/form-types build",
87
"build:form-view": "pnpm -F @coding-form/form-view build",
9-
"build": "pnpm run build:form-types && pnpm run build:form-view",
8+
"build": "pnpm run build:form-view",
109
"watch:form-view": "pnpm -F @coding-form/form-view dev",
1110
"dev:app-pc": "pnpm -F @form-example/app-pc dev",
1211
"dev:app-mobile": "pnpm -F @form-example/app-mobile dev",

packages/form-types/.gitignore

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/form-types/AGENTS.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/form-types/README.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/form-types/package.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/form-types/rslib.config.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)