vigetlabs / ca11y

A lightweight accessible dependency-free datepicker
http://code.viget.com/ca11y
26 stars 6 forks source link

Add callback param #13

Closed greypants closed 8 years ago

greypants commented 8 years ago

For doing things like custom date parsing. We probably shouldn't even touch the date input... let the implementer do that in the callback. Ideally I'd like the setup to be something like:

import Ca11y  from 'ca11y'
import options from 'ca11y/defaults'
import parse   from 'ca11y/parse'

const someInput = document.querySelector('#some-input')

function callback(selectedDateObject) {
  someInput.value = parse(selectedDateObject, 'mm/dd/yyyy')
}

const datePicker = new Ca11y(options, callback)
solomonhawk commented 8 years ago

I mentioned this in a few other issues I'm kicking around. I think it would be nice if we expose a variety of callbacks for different events within Ca11y and expose them as properties of options.

What do you think about having an optional element option which, when present, would directly attach Ca11y to the input. When omitted, the user would be responsible for:

1) providing an onDaySelected callback that receives the selected date from Ca11y and renders it into the form input 2) adding a change event listener to the input that, when fired, parses the input value and if it is a valid date, calls back to the Ca11y instance and tells it to update it's internal state

Still thinking on this a bit.