Can I debounce a checkbox input in Aurelia?
Asked Answered
S

1

6

I'm trying to use the debounce binding behaviour on a list of checkboxes, but it doesn't seem to be working the way I expect (I'm not sure if you can even debounce a checkbox):

<label repeat.for="v of values">
  <input type="checkbox" value.bind="v" checked.bind="checkedVal & debounce:1000"> Checkbox value "${v}"
</label>

clicking on any of the checkboxes results in the checkedVal array updating immediately, whereas it works as I expect for a normal input:

<input type="text" value.bind="textVal & debounce:1000"/>

Can I debounce a checkbox input?

Here's the full code, with a GistRun here. app.html:

<template>
  <h1>Checkbox bind debounce</h1>
  <form>
    <label for="text">text input with debounce:1000 </label>
    <input type="text" value.bind="textVal & debounce:1000"/>
    <div repeat.for="v of values">
      <br/>
      <label>
        <input type="checkbox" value.bind="v" checked.bind="checkedVal & debounce:1000"> Checkbox value "${v}"
      </label>
    </div>
  </form>
  <br/>
  <p>Text value: ${textVal}</p>
  <p>Checked values:</p>
  <p repeat.for="v of checkedVal">${v}</p>
</template>

app.js:

export class App {
  values = [1, 2, 3];
  checkedVal = [];
}

Thanks!

Sadfaced answered 10/2, 2017 at 3:10 Comment(4)
Hmm, looks like an Aurelia bug.Cauterize
I'm not sure if this is supported... Interesting question thoughIsidor
I'm gonna pass this to Jeremy, this might be a bug. As a question, what's the desire to debounce a checkbox? Are you expecting the user to ciick it a bunch really quickly?Septa
@AshleyGrant I'm expecting that they'll select 2-3 checkboxes fairly quickly, and I'm trying to stop server-side validation from triggering after each one.Sadfaced
S
4

At this time, it's not supported. The debounce binding behavior controls the rate at which the checkedVal property is assigned. In a checked binding, the property isn't assigned, the array instance referenced by the property is mutated with push and splice which circumvents the debouncing in the binding expression.

Sochi answered 11/2, 2017 at 13:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.