Problem/Motivation
HTML5 offers an type of "search", that adds accessible functionality to a regular text input. This is not currently available via the Form API.
Proposed resolution
Add a #type to the Form API called 'search', that will output the form element with: type="search". Change some of the core input fields that would be more appropriate as a search to this input type. Add a "form-search" class to the field's output and add input.form-search selector to some core CSS files for uniformity (making it look normal in Bartik).
Remaining tasks
Some question remains as to whether we should style all search inputs or only those in #search-form and #block-search-form with this patch. The Bartik maintainers should decide on this.
User interface changes
In browsers that support the "search" input type, when users start typing, an 'x' on the very right inside the search box will appear, allowing them to clear the field.
API changes
A search input box can be added to a form with the '#type' attribute:
$form['myelement']['#type'] => 'search',
Original report by Dave Reid
Split from #675348: META: Support HTML5 form input elements to add a new 'searchfield' Form API element.
This is an easy win element. No additional validation, and we can easily use it in search.module right away.
--
The HTML5 Groups seems to be in agreement with the current implementation.
This patch adds the Search form Element, uses it in the search block/page, and adds the same test we've been adding to all the new form elements.
This patch also adds some minor Bartik css just to keep the same look, but it doesn't touch the other themes, or the actual search.css.
Comment | File | Size | Author |
---|---|---|---|
#33 | seven-before-and-after.png | 4.85 KB | Niklas Fiekas |
#33 | stark-before-and-after.png | 7.3 KB | Niklas Fiekas |
#32 | bartik-search-before.png | 10.09 KB | Jacine |
#32 | bartik-search-after.png | 9.98 KB | Jacine |
#24 | 1174628-html5-search-24.patch | 9.19 KB | Niklas Fiekas |
Comments
Comment #1
Dave ReidInitial patch for review and converted search.module's use and anywhere we have a text area for 'filtering' on a string, like the URL alias or Filter translatable strings UI.
Comment #2
Dave Reid#1: 1174628-html5-search-element.patch queued for re-testing.
Comment #4
Dave ReidComment #5
droplet CreditAttribution: droplet commentedMissing #placeholder ?
and more ??
http://www.w3.org/TR/html-markup/input.search.html#input.search
Powered by Dreditor.
Comment #6
Dave ReidThe other attributes are not specific to search element and can be or already are follow-up issues.
Comment #7
sunI don't think we should add the .form-text class here. Such double-classes complicate theming/styling.
Powered by Dreditor.
Comment #8
Dave ReidOur core themes do waaay too much with .form-text. Feel free to re-roll as there are lots of issues relating to styling if its not present.
Comment #9
droplet CreditAttribution: droplet commentedI think we need it.
is it array rendering sequentially??
it should
Comment #10
Dave ReidYep, had the wrong order.
Comment #11
ericduran CreditAttribution: ericduran commentedDo we want to add placeholder on this patch?
There's already an issue for placeholder.
Comment #12
Dave ReidThe element supports placeholder already, I figured to avoid bikeshed not to add a placeholder for any of the instances of it. If we can get a consensus, I'd be up for adding it here.
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commented#placeholder has been committed: #1174694: Allow FAPI usage of the placeholder attribute. It should probably be added to this patch.
Comment #14
Dave ReidAttempt at a re-roll.
Comment #15
Dave ReidComment #16
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedGo, testbot, go!
Comment #18
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedOk. Rebased and fixed the half-trivial merge conflicts. Let's see how this does in testing.
Note that it looks like this in Bartik, so I guess the CSS needs to be fixed, too:
Comment #20
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedhttp://css-tricks.com/webkit-html5-search-inputs/ might or might not be helpful for someone trying to fix the CSS. It also shows that there are quiet some limitations for how this element can be styled.
Comment #21
ericduran CreditAttribution: ericduran commentedThis one should fix the test.
Comment #22
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedIt did. Thanks. Now back to needs work for fixing the CSS?
Comment #23
JacineI'll see what I can do here this sprint.
Comment #24
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedRebased because #1174630: Add new HTML5 FAPI element: url and #1174620: Add new HTML5 FAPI element: email got in :)
Needs review for the testbot.
Comment #25
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedAnd needs work for jacine ;)
Comment #26
JacineSorry for taking so long to get to this. Here's a re-rolled patch that includes fixes for Bartik and some screenshots. I tested in Chrome, Firefox, IE8/9 and Opera and it looks consistent across all of them. Hopefully it's what you guys were looking for.
Comment #27
ericduran CreditAttribution: ericduran commentedThis looks good, personally I don't like the -webkit-appearance: textfield :-p but is only in the Bartik css so that's cool :)
Comment #28
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedWow! Excellent! Thank you. I didn't even believe that could be done.
Three questions:
input[type="search"]
vs.form-type-search input
?Does this hide the X to clear the input in some browsers? If so: Should we really be doing that?
#search-form
and#block-search-form
?Comment #30
hass CreditAttribution: hass commentedI've also asked me this and why we remove the input X as this seams the only reason for using the search element. Why is the apperance set to textfield in bartic only and not the other themes and how to repro the issue. There is no screenshot how it looks without the change.
It may also be useful to use results=5 and autosave=uniquekey on search fields.
Comment #31
JacineHey guys.
In response to #29:
1. input[type="search"] is shorter. The other example is IE6 style CSS IMO. Not a big deal either way though. :)
2. No, no, no. It doesn't remove the X. That's a different pseudo element:
input[type="search"]::-webkit-search-cancel-button
. Did you guys look at the Chrome screenshot? The X is clearly there. This pseudo element just resets some default padding that Webkit browsers provide. It only affects Webkit and is perfectly safe. See Formalize and Normalize libraries, which set them as global resets.3. You guys told me you wanted to match what Bartik originally looked like and that you needed help, so here I am. LOL. As for whether to style it globally, I dunno. I'd rather leave that up to Bartik maintainers. All I'm trying to do here is prevent a visual regression from D7. Anyway, it's unfair to hold up getting the search element in right now because of Bartik, so I am leaning toward committing this, and opening a follow up to give the Bartik maintainers the option to do something else, if they see fit.
#30
- Before and after is attached. Note, it's only a webkit thing and it's not a bug persay, just how webkit styles it, and it looks crappy in bartik because of the way bartik styles the search form.
- Regarding the results and autosave attributes, I don't think we should put those in by default, but I think it might make sense to add them as properties. What does everyone else think?
Comment #32
JacineOops. Now before and afters are attached.
Comment #33
Niklas Fiekas CreditAttribution: Niklas Fiekas commented#29:
1. Excellent.
2. Excellent. (Yep, I did look at the screenshots, just asked to be sure that doesn't hide it in other browsers.)
3. Excellent ;)
#30:
Actually we did have before screenshots already. No problem at all.
Since "we want the search element" is pretty clear, but "should we add properties for result and autosave, or leave it attributes, and/or give them default values, and/or use default values for the search module" needs discussion, I'd say that'd be a follow up issue. No?
Not to forget: Thank you, Jacine, again! And indeed: We only needed Bartik. For Seven and Stark it looks exactly the same before and after. (Except for the X).
Comment #34
ericduran CreditAttribution: ericduran commentedOk, awesome. It seems like we're all in agreement.
I'm updating the Issue summary now.
Comment #34.0
ericduran CreditAttribution: ericduran commentedUpdated issue summary.
Comment #35
catchThanks folks. Committed/pushed to 8.x.
Comment #36
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedYay! Should we add a note to http://drupal.org/node/1315186?
Comment #37
aspilicious CreditAttribution: aspilicious commentedYes :)
Comment #38
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedAlright, done ;)
Comment #39.0
(not verified) CreditAttribution: commentedAdded an issue summary.