HTML5 required attribute for some input forms
This commit is contained in:
parent
0777aa5487
commit
a2a2105058
@ -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(
|
||||
|
@ -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'),
|
||||
|
@ -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();
|
||||
|
@ -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');
|
||||
|
@ -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');
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user