Skip to content

Commit 8afc05c

Browse files
authored
Merge pull request #5 from tkc/fix/form
Fix From validation
2 parents 3aca33f + ca0373d commit 8afc05c

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/components/molecules/form-kit/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ export const validater = validate;
1212
export interface InputPropsBase {
1313
name: string;
1414
renderProps: FormikProps<any>;
15-
validater: (value: string) => string | undefined;
15+
validater?: (value: string) => string | undefined;
1616
placeholder?: string;
1717
}
1818

1919
export interface InputProps extends InputPropsBase {
2020
size: "small" | "default" | "large";
2121
type: "password" | "text" | "email";
22+
defaultValue: string;
2223
}
2324

2425
export function input(props: InputProps) {
@@ -34,7 +35,7 @@ export function input(props: InputProps) {
3435
size={props.size}
3536
onBlur={props.renderProps.handleBlur}
3637
onChange={props.renderProps.handleChange}
37-
defaultValue={props.renderProps.values.password}
38+
defaultValue={props.defaultValue}
3839
placeholder={props.placeholder}
3940
/>
4041
);
@@ -46,6 +47,7 @@ export function input(props: InputProps) {
4647
export interface TextAreaProps extends InputPropsBase {
4748
type: "password" | "text" | "email";
4849
rows: number;
50+
defaultValue: string;
4951
}
5052

5153
export function textArea(props: TextAreaProps) {
@@ -60,7 +62,7 @@ export function textArea(props: TextAreaProps) {
6062
name={props.name}
6163
onBlur={props.renderProps.handleBlur}
6264
onChange={props.renderProps.handleChange}
63-
defaultValue={props.renderProps.values.password}
65+
defaultValue={props.defaultValue}
6466
placeholder={props.placeholder}
6567
rows={props.rows}
6668
/>
@@ -71,7 +73,6 @@ export function textArea(props: TextAreaProps) {
7173
}
7274

7375
export interface SelectInputProps extends InputPropsBase {
74-
defaultValue: string | null;
7576
options: { key: string; value: string }[];
7677
}
7778

src/components/pages/account/form.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function AccountForm(props: AccountFormProps) {
2121
<>
2222
<Helmet title="Product Edit" />
2323
<Formik
24-
initialValues={{ name: "name", description: "password", size: "size", loading: false }}
24+
initialValues={{ name: "name", description: "description", size: "size", loading: false }}
2525
onSubmit={(param: FormValues, actions: FormikActions<FormValues>) => {
2626
// props.onSubmit(param);
2727
}}
@@ -45,6 +45,7 @@ export function AccountForm(props: AccountFormProps) {
4545
size: "default",
4646
type: "text",
4747
placeholder: "Product title",
48+
defaultValue: "name",
4849
})}
4950
{FormKit.erroeMessage({ name: "name", renderProps })}
5051
</Form.Item>
@@ -60,6 +61,7 @@ export function AccountForm(props: AccountFormProps) {
6061
rows: 3,
6162
type: "text",
6263
placeholder: "",
64+
defaultValue: "description",
6365
})}
6466
{FormKit.erroeMessage({ name: "description", renderProps })}
6567
</FormItem>
@@ -74,8 +76,6 @@ export function AccountForm(props: AccountFormProps) {
7476
{FormKit.selectInput({
7577
name: "colors",
7678
renderProps,
77-
validater: FormKit.validater.validateSimplaInput(100),
78-
defaultValue: "red",
7979
placeholder: "Select a color",
8080
options: [
8181
{ key: "blue", value: "blue" },

src/components/pages/user/login/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const Login = (props: LoginProps) => {
5353
validater: FormKit.validater.validateEmail(),
5454
size: "default",
5555
type: "email",
56+
defaultValue: "",
5657
})}
5758
{FormKit.erroeMessage({ name: "email", renderProps })}
5859
</Form.Item>
@@ -63,6 +64,7 @@ export const Login = (props: LoginProps) => {
6364
validater: FormKit.validater.validatePaaword(),
6465
size: "default",
6566
type: "password",
67+
defaultValue: "",
6668
})}
6769
{FormKit.erroeMessage({ name: "password", renderProps })}
6870
</Form.Item>

0 commit comments

Comments
 (0)