bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

feat(editable): DOM awareness discussion

Open hallister opened this issue 13 years ago • 1 comments

I recently made an editable input for a project. I've been spending some time with it, wondering if we can really make this thing DOM-agnostic. Here's a gist of my work so far:

https://gist.github.com/hall5714/6187144

The struggle with an editable like this is normally we'd expect certain behaviors (a form, a form control of some sort (input, select, etc). However the datepicker and timepicker (or some sort of dropdown selector), are perfect examples of "editable" controls that don't follow this DOM outline.

In the gist above I have a working editable that requires no form element (but uses it for validation if it exists) and requires no specific input type (it uses a template, and that template has no DOM requirements). In fact, the editable component doesn't even require an at all, which is how we allow things like timepicker and datepicker not to look weird.

But in order to make validation work we have to put various validation attributes in the template (required, min, minlength). But since the directive has no idea what the form control in the template is, I introduced a class "wg-editable-validators". Any element with this class gets all of the validation attributes added to it.

Since this is an invitation for discussion, here's a few things I'm thinking:

  • Is this class-based selectors approach a good idea, or no?
    • If yes, should we come up with a standard class naming convention for directives that overlap?
    • If no, what's another approach?
  • In my above gist, ng-blur and ng-focus would add some cool benefits, such as the form "cancels" when the control has been blurred for X amount of time, or ng-keypress would cancel if it's an escape. But those aren't available in stable, should we add the features anyway since angular will just ignore unknown directives?

Since the goal is to make these directives DOM-unaware, I think there needs to be a standard way of grabbing elements we need, without have a specific requirement for what those elements are.

hallister avatar Aug 08 '13 18:08 hallister

Going to close this for now. I figure the simple method is to use a class directive, combined with an (eventual) move to a prefix (wg-, etc) would solve the problem. Will PR the editable in a day or two (it's been completely refactored so the above gist is moot).

hallister avatar Aug 10 '13 19:08 hallister