ghiscoding / Aurelia-Bootstrap-Plugins

Aurelia-Bootstrap-Plugins are Custom Elements to bridge with a set of 3rd party Bootstrap addons
https://ghiscoding.github.io/Aurelia-Bootstrap-Plugins
MIT License
45 stars 23 forks source link

Global format and keyboard input #6

Closed thejaff2 closed 7 years ago

thejaff2 commented 7 years ago

main.ts:

.plugin('aurelia-bootstrap-datetimepicker', config => { config.options.format = 'YYYY-MM-DD'; }

view.ts:

<abp-datetime-picker model.bind="startdate" ></abp-datetime-picker>

viewmodel.ts:

this.startdate = new Date(2017, 3, 1);

Upon first load it shows this: image

But when given focus it displays correctly: image

It also reverts back to the long format when trying to change it with keyboard, so it is not possible to enter date this way. My guess is that the binding should not trigger to use moment() until the input loses focus (ie when the user is finished writing)

thejaff2 commented 7 years ago

Does work when using non-global options though (strange, since global format worked in 1.0.3):

<abp-datetime-picker model.bind="startdate" options.bind="{ format: 'YYYY-MM-DD' }" ></abp-datetime-picker>

ghiscoding commented 7 years ago

in the latest code, I also refactored how I get the format, it might have affected the global. I actually haven't tried to just use the format in the Global config, that's a good point but I actually didn't think about that. Will have to revisit my code later.

ghiscoding commented 7 years ago

Fixed the Global format, the custom options (in View or ViewModel) will have priority over the global options.

I definitely will have to look into adding unit testing for these, however that will have to wait since I'm going in vacation in a week.

By the way, I saw you using TypeScript, which I haven't worked with yet. Is there something to add in my plugin to cover both TypeScript/non-TypeScript? Do you have to use the type {any} somewhere in your code because I'm not defining types or...? I'm just not familiar with it yet, any guidance would help. I might add that later if this could help anyhow.

thejaff2 commented 7 years ago

It works now, great.

You dont have to add any typings for it to work with TypeScript, it is a bonus though. Writing large complex business applications should not be done with plain JavaScript (even TypeScript is a barely a good-enough solution imo).