Skip to content

Commit

Permalink
example: input error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkolind committed Nov 27, 2023
1 parent 9f678c5 commit da550e8
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions example/components/todo/input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,42 @@ const TodoInput = {
name: 'todo-input',
template: html`
<div>
<input type="text" />
<button id="add-btn">Add</button>
<div>
<input type="text" />
<button id="add-btn">Add</button>
</div>
<span o-text="error"></span>
</div>
`,
state: {
text: '',
error: '',
},
setup({ query, state, parent }) {
const input = query('input')
const btn = query('#add-btn')
const error = query('[o-text="error"]')

const { show, hide } = error.if({ initial: false })

input.on('input', function () {
state.text = input.value
})

btn.on('click', function () {
if (state.text === '') {
state.error = 'Please enter a todo'
show()

return
}

hide()

parent.events.add(state.text)

state.text = ''
input.value = ''
})
},
}
Expand Down

0 comments on commit da550e8

Please sign in to comment.