-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added number example at TextInputImpl.
- Loading branch information
1 parent
185a0fe
commit dd60b56
Showing
4 changed files
with
27 additions
and
20 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 +1 @@ | ||
{ "singleQuote": true, "printWidth": 120 } | ||
{ "singleQuote": true, "printWidth": 120, "tabWidth": 2 } |
3 changes: 2 additions & 1 deletion
3
packages/lib/examples/implementations/NestedArrFieldImpl/index.tsx
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
38 changes: 21 additions & 17 deletions
38
packages/lib/examples/implementations/TextInputImpl/index.tsx
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,30 +1,34 @@ | ||
import { Component } from 'solid-js'; | ||
import { TextInput } from '@example-components'; | ||
import { useFormHandler } from '@hooks'; | ||
import { ValidationSchema } from '@interfaces'; | ||
|
||
export const TextInputImpl: Component<{ schema: ValidationSchema<any> }> = (props) => { | ||
const formHandler = useFormHandler(props.schema); | ||
|
||
const submit = async (event: Event) => { | ||
event.preventDefault(); | ||
try { | ||
await formHandler.validateForm(); | ||
alert(JSON.stringify(formHandler.formData())); | ||
formHandler.resetForm(); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<div> | ||
<form onSubmit={submit}> | ||
<h3>Text input implementation</h3> | ||
<label>Name</label> | ||
<br /> | ||
<input | ||
data-testid="test-input" | ||
name="name" | ||
placeholder="Write your name" | ||
oninput={({ currentTarget: { name, value } }) => formHandler.setFieldValue(name, value)} | ||
onblur={({ currentTarget: { name } }) => formHandler.validateField(name)} | ||
></input> | ||
{formHandler.isFieldInvalid('name') && ( | ||
<> | ||
<br /> | ||
<small style="color: red">{formHandler.getFieldError('name')}</small> | ||
</> | ||
)} | ||
</div> | ||
<div class="mb-3"> | ||
<TextInput data-testid="test-input" formHandler={formHandler} name="name" placeholder="Write your name" /> | ||
</div> | ||
<div class="mb-3"> | ||
<TextInput formHandler={formHandler} name="age" placeholder="Write your age" type="number" /> | ||
</div> | ||
<button>Submit</button> | ||
</form> | ||
</> | ||
); | ||
}; |
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