Implemented +/- buttons for episode count (closes #72)

This commit is contained in:
Eduard Urbach 2017-11-16 22:54:42 +01:00
parent abfad585e8
commit e8aed98b3c
2 changed files with 16 additions and 3 deletions

View File

@ -18,9 +18,9 @@ component InputNumberWithButtons(id string, value float64, label string, placeho
label(for=id)= label + ":"
.number-input-container
input.widget-ui-element.action(id=id, data-field=id, type="number", value=value, min=min, max=max, step=step, placeholder=placeholder, title=placeholder, data-action="save", data-trigger="change")
button
button.action(data-action="addNumber", data-trigger="click", data-id=id, data-add="1")
RawIcon("plus")
button
button.action(data-action="addNumber", data-trigger="click", data-id=id, data-add="-1")
RawIcon("minus")
component InputSelection(id string, value string, label string, placeholder string, options []*arn.Option)

View File

@ -5,7 +5,7 @@ export function save(arn: AnimeNotifier, input: HTMLElement) {
let obj = {}
let isContentEditable = input.isContentEditable
let value = isContentEditable ? input.innerText : (input as HTMLInputElement).value
if(value === undefined) {
return
}
@ -77,4 +77,17 @@ export function increaseEpisode(arn: AnimeNotifier, element: HTMLElement) {
let episodes = parseInt(prev.innerText)
prev.innerText = String(episodes + 1)
save(arn, prev)
}
// Add number
export function addNumber(arn: AnimeNotifier, element: HTMLElement) {
if(arn.isLoading) {
return
}
let input = arn.app.find(element.dataset.id) as HTMLInputElement
let add = parseInt(element.dataset.add)
let num = parseInt(input.value)
input.value = (num + add).toString()
save(arn, input)
}