Skip to content

Add methods for finding labels and forms for controls#1546

Closed
arschmitz wants to merge 21 commits into
jquery:masterfrom
arschmitz:input-methods
Closed

Add methods for finding labels and forms for controls#1546
arschmitz wants to merge 21 commits into
jquery:masterfrom
arschmitz:input-methods

Conversation

@arschmitz
Copy link
Copy Markdown
Member

This adds 2 new $.fn methods to core, and a new prop to $.ui.escapeId.

$.fn.labels which mimics the native control.labels ( and uses it where possible ). This method unlike the native property also works on detached DOM nodes, and in browsers not supporting control.labels.

$.fn.form which fixes the native control.form in IE8 where setting the form attribute breaks the form property by changing it to a string.

$.ui.escapeId is a regex for escaping id and similar to be able to use them as jQuery selectors. Its needed anytime you are building a selector from the id or some other attribute of an element because there are characters valid in the HTML that need to be escaped when used as a selector.

This also updates selectmenu to use both $.fn.labels and $.ui.escapeId and it updates tabs to use $.ui.escapeId. $.fn.form is needed both by checkboxradio in the button rewrite but also by the from reset extension @scottgonzalez is working on. Checkboxradio will also use $.ui.escapeId. jquery-mobile will also use all three of these.

Note: This does add 3 new exceptions to htmllint:bad for the labels tests. These are needed to make sure we match that native implementation. While the markup may not be valid it is supported by every browser, so it is required otherwise we could get label / input mismatches which would break visual state and underlying state consistency for inputs and labels in things like checkboxradio. Specifically this can happen with inputs wrapped in multiple labels, and inputs which are wrapped in a label which is associated with an input besides the one it contains based on its for attribute.

@arschmitz arschmitz added this to the 1.12 milestone Apr 27, 2015
@arschmitz arschmitz changed the title Input methods Add methods for finding labels and forms for controls Apr 27, 2015
@scottgonzalez
Copy link
Copy Markdown
Member

While the markup may not be valid it is supported by every browser

It doesn't matter what happens natively if it's invalid markup. We never support invalid markup.

Comment thread Gruntfile.js Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this duplicated?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mistake

@scottgonzalez
Copy link
Copy Markdown
Member

Since removing support for nested labels is likely to change a lot, I'll wait before reviewing this.

@arschmitz
Copy link
Copy Markdown
Member Author

It only actually removes the filter here https://github.com/jquery/jquery-ui/pull/1546/files#diff-9642379d08d860be4c2831b0ff5b9a85R168 which is why i think making sure we have the proper label to ensure the DOM matches the state of the widget is more important then saying we don't support invalid markup.

@scottgonzalez
Copy link
Copy Markdown
Member

It doesn't matter how small the code is for the support. Invalid markup is never supported and we absolutely should not test against it.

Comment thread tests/unit/core/core.html Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer relevant.

@arschmitz
Copy link
Copy Markdown
Member Author

All updated

Comment thread tests/unit/core/core.html
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you mean that these are not in the test fixture, No. Though i did mean to add a comment to explain why.
If you place these in the test fixture they get reset / replaced between each async test which is not what i want. because then any saved references are to a detached fragment, not attached DOM which i specifically want to test.

@arschmitz
Copy link
Copy Markdown
Member Author

@scottgonzalez updated

Comment thread tests/unit/core/core.html
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better :-) Just need to start with a capital letter here.

@scottgonzalez
Copy link
Copy Markdown
Member

Just a few minor things. You can land this after making those updates.

@arschmitz arschmitz closed this in 803eaf2 May 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants