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
Comments
Removed Type-Defect label. |
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, ... { abstract class TextElement implements Element { abstract class CheckboxElement implements Element { 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. |
Issue #6673 has been merged into this issue. |
Added this to the M3 milestone. |
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): |
Added Fixed label. |
Awesome! |
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;
The text was updated successfully, but these errors were encountered: