-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from SouJunior/validations
Validações feitas
- Loading branch information
Showing
4 changed files
with
208 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import JobForm from '../components/molecules/JobForm/index' | ||
import JobForm from "../components/molecules/JobForm/index"; | ||
|
||
export default function Home() { | ||
return ( | ||
<> | ||
<JobForm></JobForm> | ||
<JobForm/> | ||
</> | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,84 @@ | ||
import { Label } from './label'; | ||
import { ContainerInput , Field } from './style' | ||
import React, { useState } from 'react' | ||
import { useField } from "formik"; | ||
import { Label } from "./label"; | ||
import { ContainerInput, Field, StyledError } from "./style"; | ||
|
||
interface InputFormProps { | ||
id: string; | ||
name: string; | ||
type?: string; | ||
placeholder?: string; | ||
label: string | ||
width: string | ||
height?: string | ||
as?: string | ||
options?: Array<string> | ||
id: string; | ||
name: string; | ||
type?: string; | ||
placeholder?: string; | ||
label: string; | ||
width: string; | ||
height?: string; | ||
as?: string; | ||
options?: Array<string>; | ||
minDate?: string; | ||
maxDate?: string; | ||
callback?: (value: string) => void; | ||
} | ||
|
||
export default function InputForm({ | ||
id, | ||
name, | ||
type, | ||
placeholder, | ||
label, | ||
width, | ||
height, | ||
as, | ||
options, | ||
} : InputFormProps) { | ||
const [selectedValue, setSelectedValue] = useState(''); | ||
id, | ||
name, | ||
type, | ||
placeholder, | ||
label, | ||
width, | ||
height, | ||
as, | ||
options, | ||
minDate, | ||
maxDate, | ||
callback, | ||
}: InputFormProps) { | ||
const [field] = useField(name); | ||
|
||
const handleSelectChange = (event: any) => { | ||
setSelectedValue(event.target.value); | ||
console.log(event.target.value); | ||
}; | ||
const handleSelectChange = (event: any) => { | ||
if (callback) { | ||
callback(event.target.value); | ||
} | ||
|
||
return ( | ||
<ContainerInput> | ||
<Label | ||
htmlFor={id} | ||
name={label} | ||
/> | ||
{as === 'select' ? | ||
<Field | ||
id={id} | ||
name={name} | ||
width={width} | ||
height={height} | ||
as={as} | ||
onChange={handleSelectChange} | ||
value={selectedValue} | ||
> | ||
{options?.map((op, index) => ( | ||
<option key={index} value={index > 0 ? op : ""}> | ||
{op} | ||
</option> | ||
))} | ||
</Field> | ||
: | ||
<Field | ||
id={id} | ||
name={name} | ||
type={type} | ||
placeholder={placeholder} | ||
width={width} | ||
height={height} | ||
/> | ||
} | ||
</ContainerInput> | ||
); | ||
} | ||
field.onChange(event); | ||
}; | ||
|
||
return ( | ||
<ContainerInput> | ||
<Label htmlFor={id} name={label} /> | ||
{as === "select" ? ( | ||
<> | ||
<Field | ||
id={id} | ||
name={name} | ||
width={width} | ||
height={height} | ||
as={as} | ||
onChange={handleSelectChange} | ||
value={field.value} | ||
> | ||
{options?.map((op, index) => ( | ||
<option key={index} value={index > 0 ? op : ""}> | ||
{op} | ||
</option> | ||
))} | ||
</Field> | ||
<StyledError name={name} component="span" /> | ||
</> | ||
) : ( | ||
<> | ||
<Field | ||
id={id} | ||
name={name} | ||
type={type} | ||
placeholder={placeholder} | ||
width={width} | ||
height={height} | ||
min={minDate} | ||
max={maxDate} | ||
/> | ||
|
||
<StyledError name={name} component="span" /> | ||
</> | ||
)} | ||
</ContainerInput> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.