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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Needs review
FileSize
5.78 KB

Initial 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.

Dave Reid’s picture

Issue tags: -html5

#1: 1174628-html5-search-element.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +html5

The last submitted patch, 1174628-html5-search-element.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
6.39 KB
droplet’s picture

Status: Needs review » Needs work
+++ b/includes/form.incundefined
@@ -3635,8 +3635,48 @@ function theme_textfield($variables) {
+  element_set_attributes($element, array('type', 'id', 'name', 'value', 'size', 'maxlength'));

Missing #placeholder ?

and more ??
http://www.w3.org/TR/html-markup/input.search.html#input.search

Powered by Dreditor.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
6.42 KB

The other attributes are not specific to search element and can be or already are follow-up issues.

sun’s picture

+++ b/includes/form.inc
@@ -3635,8 +3635,48 @@ function theme_textfield($variables) {
+  _form_set_class($element, array('form-search', 'form-text'));

I don't think we should add the .form-text class here. Such double-classes complicate theming/styling.

Powered by Dreditor.

Dave Reid’s picture

Our 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.

droplet’s picture

I think we need it.

is it array rendering sequentially??
it should

+  _form_set_class($element, array('form-text', 'form-search'));
Dave Reid’s picture

Yep, had the wrong order.

ericduran’s picture

Do we want to add placeholder on this patch?

There's already an issue for placeholder.

Dave Reid’s picture

The 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.

Anonymous’s picture

Status: Needs review » Needs work

#placeholder has been committed: #1174694: Allow FAPI usage of the placeholder attribute. It should probably be added to this patch.

Dave Reid’s picture

Attempt at a re-roll.

Dave Reid’s picture

Niklas Fiekas’s picture

Status: Needs work » Needs review

Go, testbot, go!

Status: Needs review » Needs work

The last submitted patch, 1174628-html5-search-element.patch, failed testing.

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
9.8 KB
8.58 KB

Ok. 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:
html5-search.png

Status: Needs review » Needs work

The last submitted patch, 1174628-html5-search-18.patch, failed testing.

Niklas Fiekas’s picture

http://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.

ericduran’s picture

Status: Needs work » Needs review
FileSize
9.13 KB

This one should fix the test.

Niklas Fiekas’s picture

Status: Needs review » Needs work

It did. Thanks. Now back to needs work for fixing the CSS?

Jacine’s picture

Assigned: Dave Reid » Jacine
Issue tags: +sprint

I'll see what I can do here this sprint.

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
9.19 KB

Rebased because #1174630: Add new HTML5 FAPI element: url and #1174620: Add new HTML5 FAPI element: email got in :)
Needs review for the testbot.

Niklas Fiekas’s picture

Status: Needs review » Needs work

And needs work for jacine ;)

Jacine’s picture

Category: feature » task
Status: Needs work » Needs review
FileSize
9.83 KB
197.56 KB
209.69 KB
175.41 KB
101.48 KB

Sorry 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.

ericduran’s picture

Status: Needs review » Reviewed & tested by the community

This looks good, personally I don't like the -webkit-appearance: textfield :-p but is only in the Bartik css so that's cool :)

Niklas Fiekas’s picture

Wow! Excellent! Thank you. I didn't even believe that could be done.

Three questions:

  • Are there reasons using input[type="search"] vs .form-type-search input?
  • +#block-search-form input[type="search"]::-webkit-search-decoration {
    +  display: none;
    +}

    Does this hide the X to clear the input in some browsers? If so: Should we really be doing that?

  • Should we style all search inputs or only those in #search-form and #block-search-form?
hass’s picture

I'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.

Jacine’s picture

Hey 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?

Jacine’s picture

Oops. Now before and afters are attached.

Niklas Fiekas’s picture

#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).

ericduran’s picture

Ok, awesome. It seems like we're all in agreement.

I'm updating the Issue summary now.

ericduran’s picture

Issue summary: View changes

Updated issue summary.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks folks. Committed/pushed to 8.x.

Niklas Fiekas’s picture

Yay! Should we add a note to http://drupal.org/node/1315186?

aspilicious’s picture

Yes :)

Niklas Fiekas’s picture

Alright, done ;)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Added an issue summary.