File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
2-desenvolvimento-front-end/DR2-fundamentos-de-react/DR2-AT-ecommerce-dummy-crud/src/pages/product-form Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import axios from 'axios';
44import style from './style.module.css' ;
55
66export default function ProductForm ( ) {
7- const { register, handleSubmit } = useForm ( ) ;
7+ const { register, handleSubmit, formState : { errors } } = useForm ( ) ;
88 const navigate = useNavigate ( ) ;
99
1010 const onSubmit = async ( data ) => {
@@ -33,26 +33,29 @@ export default function ProductForm() {
3333 < input
3434 id = "title"
3535 type = "text"
36- { ...register ( 'title' ) }
36+ { ...register ( 'title' , { required : 'O título é obrigatório' } ) }
3737 />
38+ { errors . title && < span className = { style . erro } > { errors . title . message } </ span > }
3839 </ div >
3940
4041 < div className = { style . campo } >
4142 < label htmlFor = "price" > Preço:</ label >
4243 < input
4344 id = "price"
4445 type = "number"
45- { ...register ( 'price' ) }
46+ { ...register ( 'price' , { required : 'O preço é obrigatório' } ) }
4647 />
48+ { errors . price && < span className = { style . erro } > { errors . price . message } </ span > }
4749 </ div >
4850
4951 < div className = { style . campo } >
5052 < label htmlFor = "description" > Descrição:</ label >
5153 < textarea
5254 id = "description"
5355 rows = "4"
54- { ...register ( 'description' ) }
56+ { ...register ( 'description' , { required : 'A descrição é obrigatória' } ) }
5557 />
58+ { errors . description && < span className = { style . erro } > { errors . description . message } </ span > }
5659 </ div >
5760
5861 < div className = { style . campo } >
You can’t perform that action at this time.
0 commit comments