Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
Fixing bugs and adding attribute for formField in Form2
Browse files Browse the repository at this point in the history
  • Loading branch information
Javiani committed Feb 21, 2021
1 parent 0164f0c commit a29f434
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions form2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ The `form-field` component will fire 1 event:
- `focus` : Boolean, true when input element is on focus and false otherwise.
- `data` : Data containing state from parent components.
- `fieldClass` : Default classes for assigning `touched`, `focus`, `error` states.
- `value` : The value of the field if you wanna use it as a state.
2 changes: 1 addition & 1 deletion form2/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions form2/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ export default function formField ({ main, elm, msg, injection, emit, update })
* @param {*} event
*/
const onchange = (event) => {
const { name } = event.target
const { name, value } = event.target
validator({ [name]: getRules(event.target) }, validators)
.then(_ => {
msg.set(s => {
s.error = null
s.isValid = Boolean(s.touched)
s.value = value
})
})
.catch( _ => msg.set( s => s.isValid = false ))
.catch( _ => msg.set( s => {
s.isValid = false
s.value = value
}))
.finally( emitchange )
}

Expand All @@ -46,20 +50,22 @@ export default function formField ({ main, elm, msg, injection, emit, update })
* @param {*} event
*/
const onblur = (event) => {
const { name } = event.target
const { name, value } = event.target
validator({ [name]: getRules(event.target) }, validators)
.then(_ => {
msg.set(s => {
s.error = null
s.isValid = Boolean(s.touched)
s.focus = false
s.value = value
})
})
.catch(errors => {
msg.set(s => {
s.error = formatError(errors[name])
s.isValid = false
s.focus = false
s.value = value
})
})
.finally( emitchange )
Expand Down

0 comments on commit a29f434

Please sign in to comment.