Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience classes for CheckBox, TextField, etc. to dart:html #1684

Closed
justinfagnani opened this issue Feb 14, 2012 · 8 comments
Closed
Assignees
Labels
type-enhancement A request for a change that isn't a bug web-libraries Issues impacting dart:html, etc., libraries
Milestone

Comments

@justinfagnani
Copy link
Contributor

Instead of :

InputElement checkBox = new Element.tag("input");
checkBox.type = "checkbox";
bool value = (checkBox.value == "true");

It'd be much nicer to simply write:

CheckBox checkBox = new CheckBox();
bool value = checkBox.value;

@anders-sandholm
Copy link
Contributor

Removed Type-Defect label.
Added Type-Enhancement, Area-UI, Triaged labels.

@jmesserly
Copy link

I had the same thought when looking up http://dev.w3.org/html5/spec/the-input-element.html#the-input-element. A bunch of DOM properties on <input> are only valid for certain “type”s. Subtypes would be a cleaner way to model that.

I don’t know if it's technically feasible to fix this. The "type" can be mutated after the fact (could/should we prevent that?) and I'm not sure we could create the right type without intercepting all DOM calls that can return Elements (a big no-no), unless we have the capability to use ".type" as part of the type information in addition to the prototype (dunno that we've ever tried that before).

Here's a strawman solution using interfaces instead of subtypes. It's not as good but it's more feasible?

    class InputElement extends Element implements TextElement, CheckboxElement, ... {
     // same as it is now
    }

    abstract class TextElement implements Element {
     // only text stuff
    }

    abstract class CheckboxElement implements Element {
     // only checkbox stuff
    }

Still it has problems like "is CheckboxElement" would always return true, you'd have to test against .type == "checkbox".

I'm not sure it's worth it but wanted to kick off the discussion with some ideas.


cc @sethladd.

@jmesserly
Copy link

Issue #6673 has been merged into this issue.

@jmesserly
Copy link

Removed Area-UI label.
Added Area-HTML label.

@efortuna
Copy link
Contributor

efortuna commented Dec 6, 2012

Added this to the M3 milestone.

@blois
Copy link
Contributor

blois commented Dec 7, 2012

I think what John proposes works fairly well- it's definitely 'loose' as any input element could pretend to be any of these subtypes, but I think it really clarifies the API.

Nit on naming- I prefer if all of the types are *InputElement. It adds a bit for Checkbox and Button, but I think it's clearer for more of the types and avoids conflicts (with ButtonElement):
    ButtonInputElement
    CheckboxInputElement
    ColorInputElement
    DateInputElement
    DateTimeInputElement
    EmailInputElement
    FileUploadInputElement
    HiddenInputElement
    ImageButtonInputElement
    LocalDateTimeInputElement
    MonthInputElement
    NumberInputElement
    PasswordInputElement
    RadioButtonInputElement
    RangeInputElement
    ResetButtonInputElement
    SearchInputElement
    SubmitButtonInputElement
    TelephoneInputElement
    TextInputElement
    TimeInputElement
    UrlInputElement
    WeekInputElement


Set owner to @blois.
Added Accepted label.

@blois
Copy link
Contributor

blois commented Dec 11, 2012

Added Fixed label.

@sethladd
Copy link
Contributor

Awesome!

@justinfagnani justinfagnani added Type-Enhancement web-libraries Issues impacting dart:html, etc., libraries labels Dec 11, 2012
@justinfagnani justinfagnani added this to the M3 milestone Dec 11, 2012
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug web-libraries Issues impacting dart:html, etc., libraries
Projects
None yet
Development

No branches or pull requests

7 participants