ariatemplates / hashspace

JavaScript client-side template engine
http://hashspace.ariatemplates.com
Apache License 2.0
14 stars 18 forks source link

adds onupdate event handler for input and textarea #310

Closed marclaval closed 9 years ago

marclaval commented 9 years ago

As a custom attribute, this PR adds a special event on and elements. It is fired 1s after a user stops typing in a field.

2 questions:

coveralls commented 9 years ago

Coverage Status

Coverage increased (+0.05%) when pulling 93bb931e4a1e1c3adfc163ccce3b05c0e317e1d8 on mlaval:onupdate into fcab2c501e074c7efb139e2387deb5c5d315cbad on ariatemplates:master.

benouat commented 9 years ago

This sounds fine for me. Regarding the timeout I would really put a lower default value. sounds like 500ms, or even 250ms should be enough for me.

Nevertheless it should be configurable... which leads us to the question how to we provide user default parameters to a custom attribute handler ??

I would say that it could be done via a transparent way of providing associated data-custom-attr on the node itself

<input onupdate="{ctrl.onUpdate(event)}" data-onupdate-timeout="500" />

b-laporte commented 9 years ago

I am also fine with the name onupdate. I also agree with @benouat that we should add a 2nd attribute to specifiy the default timer, but I would call it update-timeout:

<input onupdate="{ctrl.onUpdate(event)}" update-timeout="1000" />

... and I would choose 500ms as default timeout as it is a reasonable time for usual client-side validation. Note: I would also create a separate playground sample as the current input sample is already cluttered, and this feature deserves some explanations. Btw. the sample could demonstrate textarea and input elements. Thx.

coveralls commented 9 years ago

Coverage Status

Coverage increased (+0.08%) when pulling 14c153487d32f3afa963ee12ce315cbef5e70f77 on mlaval:onupdate into 089caa1a7417b5fe5ca520fcb656caa0be3f9fc0 on ariatemplates:master.

piuccio commented 9 years ago

I'm not sure which is best update-timeout or data-onupdate-timeout. data-* exists to avoid cluttering and introducing compatibility problems with standard attributes.

It's unlikely in this specific case, but what if HTML* introduces an update-timeout attribute? It's less unlikely instead that a future standard might add an update event.

Anyway I think you should start considering ways to extend the core through plugins. update event is useful but it belongs to the user space. The user might want to change not only the timeout, but how it relates with other events like blur, input or change, so I believe any custom attribute should be out of the core.

Another option you might consider is to include everything in one attribute, maybe with a modifier

<input onupdate="{ctrl.onUpdate(event) | updateTimeout: 1000}" />

benouat commented 9 years ago

I know @b-laporte will disagree :smiley: but I fully agree with you @piuccio when dealing with custom-attributes.... data-* for the win !! Everyone knows them, and everyone understand just by reading that it is a custom thing.

marclaval commented 9 years ago

If we want to namespace hashspace proprietary attributes, we should do it for all of them in order to guarantee consistency. There are several in scope: model, ontap, onupdate, update-timeout, etc. We'll have to discuss if and how we would do that: hsp:*, hsp-*, data-*, nothing or something else.

About this PR, let's integrate it first and then we'll see if we refactor.