[FEATURE] Show default text in search form with HTML5 attribute
authorMario Rimann <typo3-coding@rimann.org>
Tue, 26 Jul 2011 20:39:00 +0000 (22:39 +0200)
committerSteffen Gebert <steffen.gebert@typo3.org>
Sat, 30 Jul 2011 20:10:51 +0000 (22:10 +0200)
Adds a text "Search for" in the search form input
field as long as no text has been searched for
(improves accessibility). If the doctype is set to
"html5", the text is shown as attribute
placeholder="Search for", otherwise as field value
of the input field.

Change-Id: I6944b21d44ea365ac5969e94d7743f5418962ea2
Resolves: #28347
Resolves: #17496
Reviewed-on: http://review.typo3.org/3688
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
Reviewed-by: Stefan Neufeind
Reviewed-by: Xavier Perseguers
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Steffen Gebert
Tested-by: Steffen Gebert
typo3/sysext/indexed_search/pi/class.tx_indexedsearch.php
typo3/sysext/indexed_search/pi/locallang.xml
typo3/sysext/indexed_search/pi/template_css.tmpl

index b99463a..c112e8f 100755 (executable)
@@ -1258,7 +1258,20 @@ class tx_indexedsearch extends tslib_pibase {
                $markerArray['###FORM_SUBMIT###'] = $this->pi_getLL('submit_button_label','',1);
 
                        // Adding search field value
-               $markerArray['###SWORD_VALUE###'] = htmlspecialchars($this->piVars['sword']);
+               if (isset($this->piVars['sword']) && $this->piVars['sword'] != '') {
+                       $markerArray['###SWORD_VALUE###'] = htmlspecialchars($this->piVars['sword']);
+                       $markerArray['###PLACEHOLDER###'] = '';
+               } else {
+                               // Add a HTML5 placeholder attribute if the configured doctype allows it
+                       if ($GLOBALS['TSFE']->config['config']['doctype'] === 'html5') {
+                               $markerArray['###SWORD_VALUE###'] = '';
+                               $markerArray['###PLACEHOLDER###'] = 'placeholder="' . $this->pi_getLL('default_search_word_entry') . '"';
+                       } else {
+                               $markerArray['###SWORD_VALUE###'] = $this->pi_getLL('default_search_word_entry');
+                               $markerArray['###PLACEHOLDER###'] = '';
+                       }
+               }
+
 
                        // Additonal keyword => "Add to current search words"
                if ($this->conf['show.']['clearSearchBox'] && $this->conf['show.']['clearSearchBox.']['enableSubSearchCheckBox'])       {
index e2380f5..1d5c306 100755 (executable)
@@ -6,6 +6,7 @@
        </meta>
        <data type="array">
                <languageKey index="default" type="array">
+                       <label index="default_search_word_entry">Search for</label>
                        <label index="submit_button_label">Search</label>
                        <label index="opt_type_0">Distinct word</label>
                        <label index="opt_type_1">Part of word</label>
index 6c06d47..746f534 100644 (file)
@@ -31,7 +31,8 @@
 
                <div class="tx-indexedsearch-form">
                        <label for="tx-indexedsearch-searchbox-sword">###FORM_SEARCHFOR###</label>
-                       <input type="text" name="tx_indexedsearch[sword]" value="###SWORD_VALUE###" id="tx-indexedsearch-searchbox-sword" class="tx-indexedsearch-searchbox-sword sword" />&nbsp;
+                       <input type="text" name="tx_indexedsearch[sword]" value="###SWORD_VALUE###" id="tx-indexedsearch-searchbox-sword" class="tx-indexedsearch-searchbox-sword sword" ###PLACEHOLDER#
+## />&nbsp;
                </div>
 
                <!-- ###ADDITONAL_KEYWORD### begin -->