]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
HTML5 required attribute for some input forms
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 6 Apr 2014 09:27:41 +0000 (11:27 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 6 Apr 2014 09:27:41 +0000 (11:27 +0200)
lib/htmloutputter.php
lib/noticeform.php
plugins/Bookmark/forms/bookmark.php
plugins/Bookmark/forms/initialbookmark.php
plugins/Event/forms/event.php
plugins/Poll/forms/newpoll.php
plugins/QnA/forms/qnanewanswer.php
plugins/QnA/forms/qnanewquestion.php

index 369cd5936e6a5aa9a284ec9ff4bc751758733658..f1496768b12b0b540cb9f97594aec1d72459bc5f 100644 (file)
@@ -179,6 +179,7 @@ class HTMLOutputter extends XMLOutputter
      * @param string $instructions instructions for valid input
      * @param string $name         name of the element; if null, the id will
      *                             be used
+     * @param bool   $required     HTML5 required attribute (exclude when false)
      *
      * @todo add a $maxLength parameter
      * @todo add a $size parameter
@@ -186,7 +187,7 @@ class HTMLOutputter extends XMLOutputter
      * @return void
      */
 
-    function input($id, $label, $value=null, $instructions=null, $name=null)
+    function input($id, $label, $value=null, $instructions=null, $name=null, $required=false)
     {
         $this->element('label', array('for' => $id), $label);
         $attrs = array('type' => 'text',
@@ -195,6 +196,9 @@ class HTMLOutputter extends XMLOutputter
         if (!is_null($value)) { // value can be 0 or ''
             $attrs['value'] = $value;
         }
+        if (!empty($required)) {
+            $attrs['required'] = 'required';
+        }
         $this->element('input', $attrs);
         if ($instructions) {
             $this->element('p', 'form_guide', $instructions);
@@ -527,6 +531,7 @@ class HTMLOutputter extends XMLOutputter
      * @param string $name         name of textarea; if null, $id will be used
      * @param int    $cols         number of columns
      * @param int    $rows         number of rows
+     * @param bool   $required     HTML5 required attribute (exclude when false)
      *
      * @return void
      */
@@ -538,7 +543,8 @@ class HTMLOutputter extends XMLOutputter
         $instructions = null,
         $name         = null,
         $cols         = null,
-        $rows         = null
+        $rows         = null,
+        $required     = false
     ) {
         $this->element('label', array('for' => $id), $label);
         $attrs = array(
index f4a3ecfd865cda367531100807aa4af6271b3f07..e6385e495ec75a4d12319a810761c98acb684ace 100644 (file)
@@ -208,6 +208,7 @@ class NoticeForm extends Form
                                 sprintf(_('What\'s up, %s?'), $this->user->nickname));
             // XXX: vary by defined max size
             $this->out->element('textarea', array('class' => 'notice_data-text',
+                                                  'required' => 'required',
                                                   'cols' => 35,
                                                   'rows' => 4,
                                                   'name' => 'status_textarea'),
index 20101e1effbd3e15ba68f5e9f37eacfcca272423..f577a3247791c2c2382388ee29c39f4b3f3d4216 100644 (file)
@@ -121,7 +121,8 @@ class BookmarkForm extends Form
                           _m('LABEL','URL'),
                           $this->_url,
                           null,
-                          'url');
+                          'url',
+                          true);    // HTML5 "required" attribute
         $this->unli();
 
         if (!empty($this->_thumbnail)) {
@@ -142,7 +143,8 @@ class BookmarkForm extends Form
                           _m('LABEL','Title'),
                           $this->_title,
                           null,
-                          'title');
+                          'title',
+                          true);    // HTML5 "required" attribute
         $this->unli();
 
         $this->li();
index a82941b16ad3b0571126ed515385f9ac19bc8392..e41d6b961812581cb7d5a4653c2686477d0b0f45 100644 (file)
@@ -78,7 +78,8 @@ class InitialBookmarkForm extends Form
                           _m('LABEL','URL'),
                           null,
                           null,
-                          'url');
+                          'url',
+                          true);    // HTML5 "required" attribute
         $this->unli();
 
         $this->out->elementEnd('ul');
index 8100e5903bc0df5fafb02b78dc92427f89472f46..a19fd80418ccf9d80b7b0a9a1ffaee7e7c34b9ed 100644 (file)
@@ -104,7 +104,8 @@ class EventForm extends Form
                           null,
                           // TRANS: Field title on event form.
                           _m('Title of the event.'),
-                          'title');
+                          'title',
+                          true);    // HTML5 "required" attribute
         $this->unli();
 
         $this->li();
@@ -195,7 +196,8 @@ class EventForm extends Form
                           null,
                           // TRANS: Field title on event form.
                           _m('Description of the event.'),
-                          'description');
+                          'description',
+                          true);    // HTML5 "required" attribute
         $this->unli();
 
         $this->out->elementEnd('ul');
index 309125a68621eddf22a4581976438dfb0cbe91b0..5c527c5cd24debd1db7f73bfb2bfad3c204e684b 100644 (file)
@@ -107,7 +107,9 @@ class NewpollForm extends Form
                           _m('Question'),
                           $this->question,
                           // TRANS: Field title on the page to create a poll.
-                          _m('What question are people answering?'));
+                          _m('What question are people answering?'),
+                          'question',
+                          true);    // HTML5 "required" attribute
         $this->unli();
 
         $max = 5;
@@ -128,7 +130,8 @@ class NewpollForm extends Form
                               sprintf(_m('Option %d'), $i + 1),
                               $default,
                               null,
-                              'option' . ($i + 1));
+                              'option' . ($i + 1),
+                              $i<2);   // HTML5 "required" attribute for 2 options
             $this->unli();
         }
 
index c0ae220ff1880a727276efbea4c6c309b270565c..3c67d89020423762037667da992d12087289f4f7 100644 (file)
@@ -111,7 +111,7 @@ class QnanewanswerForm extends Form
 
         $out->hidden('qna-question-id', $id, 'id');
         // TRANS: Field label.
-        $out->textarea('qna-answer', _m('Enter your answer'), null, null, 'answer');
+        $out->textarea('qna-answer', _m('Enter your answer'), null, null, 'answer', true);
     }
 
     /**
index a1a2a94483a4fd6916957a1c95c4647569d7cf28..eca01879822d2a03af8f282012ed0c684e3395ee 100644 (file)
@@ -111,7 +111,8 @@ class QnanewquestionForm extends Form
             $this->title,
             // TRANS: Field title for a new question.
             _m('The title of your question.'),
-            'title'
+            'title',
+            true    // HTML5 "required" attribute
         );
         $this->unli();
         $this->li();
@@ -122,7 +123,8 @@ class QnanewquestionForm extends Form
             $this->description,
             // TRANS: Field title for question details.
             _m('Your question in detail.'),
-            'description'
+            'description',
+            true    // HTML5 "required" attribute
         );
         $this->unli();