11import type { Meta , StoryObj } from '@storybook/react' ;
22import Form from './Form' ;
33import useForm from './useForm' ;
4- import { Button , Input , InputValidationHandler } from '..' ;
4+ import { Button , Input , InputValidationHandler , TextEditor } from '..' ;
55import React from 'react' ;
66import { validators } from '..' ;
77
@@ -18,48 +18,56 @@ export const Default: Story = {
1818 // eslint-disable-next-line react-hooks/rules-of-hooks
1919 const form = useForm ( ) ;
2020
21- const validateRepeatPassword : InputValidationHandler = ( value , formData ) => {
22- const repeat = form . state . formValues ?. getFormValue ( 'password' ) ;
23-
24- if ( ! repeat ) {
21+ const validateRepeatPassword : InputValidationHandler = ( value , formData ) => {
22+ const repeat = form . state . formValues ?. getFormValue ( 'password' ) ;
23+
24+ if ( ! repeat ) {
2525 return null ;
2626 }
2727
28- if ( repeat && ! value ) {
28+ if ( repeat && ! value ) {
2929 return 'E\' necessario ripetere la password.' ;
3030 }
31-
32- if ( value !== repeat ) {
31+
32+ if ( value !== repeat ) {
3333 return 'Le due password non corrispondono' ;
3434 }
35-
35+
3636 return null ;
3737 } ;
3838
3939 const validatePassword : InputValidationHandler = ( value : any ) => {
4040 return null ;
4141
4242 const err = validators . minCharacters ( 8 , 'La Password deve contenere almeno 8 caratteri' ) ( value ) ;
43-
43+
4444 if ( err ) {
4545 return err ;
4646 }
47-
47+
4848 return validators . isRequired ( 'La password è richiesta' ) ( value ) ;
4949 } ;
5050
51- return < Form form = { form } saveForm = { ( ) => true } >
51+ return < Form form = { form } saveForm = { ( data ) => {
52+ console . log ( data ) ;
53+ return true ;
54+ } } >
5255 < Input . FormControl >
5356 < Input . Label > Password</ Input . Label >
54- < Input { ...form . registerInput ( { name : 'password' , validators : [ validatePassword ] } ) } />
57+ < Input { ...form . registerInput ( { name : 'password' , validators : [ validatePassword ] } ) } />
5558 </ Input . FormControl >
5659 < Input . FormControl >
5760 < Input . Label > Test</ Input . Label >
58- < Input { ...form . registerInput ( { name : 'test' , validators : [ validateRepeatPassword ] } ) } />
61+ < Input { ...form . registerInput ( { name : 'test' , validators : [ validateRepeatPassword ] } ) } />
62+ </ Input . FormControl >
63+
64+ < Input . FormControl >
65+ < Input . Label > Text editor</ Input . Label >
66+ < TextEditor { ...form . registerInput ( { name : 'editor' } ) } />
5967 </ Input . FormControl >
6068 < Button type = "submit" >
6169 Save
6270 </ Button >
63- </ Form > ;
71+ </ Form > ;
6472 }
6573} ;
0 commit comments