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