mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Added html5 required attribute for select tags too
This commit is contained in:
parent
8135d405a3
commit
e11d0f829a
2 changed files with 54 additions and 0 deletions
|
@ -4191,6 +4191,32 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/select'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->select('Contact.required_one', array('option A'));
|
||||
$expected = array(
|
||||
'select' => array(
|
||||
'name' => 'data[Contact][required_one]',
|
||||
'id' => 'ContactRequiredOne',
|
||||
'required' => 'required'
|
||||
),
|
||||
array('option' => array('value' => '')), '/option',
|
||||
array('option' => array('value' => '0')), 'option A', '/option',
|
||||
'/select'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->select('Contact.required_one', array('option A'), array('disabled' => true));
|
||||
$expected = array(
|
||||
'select' => array(
|
||||
'name' => 'data[Contact][required_one]',
|
||||
'id' => 'ContactRequiredOne',
|
||||
'disabled' => 'disabled'
|
||||
),
|
||||
array('option' => array('value' => '', 'disabled' => 'disabled')), '/option',
|
||||
array('option' => array('value' => '0', 'disabled' => 'disabled')), 'option A', '/option',
|
||||
'/select'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4444,6 +4470,26 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/select'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->select('Contact.required_one', array(
|
||||
'1' => 'option A',
|
||||
'2' => 'option B'
|
||||
), array('multiple' => true));
|
||||
$expected = array(
|
||||
'input' => array(
|
||||
'type' => 'hidden', 'name' => 'data[Contact][required_one]', 'value' => '', 'id' => 'ContactRequiredOne_'
|
||||
),
|
||||
'select' => array(
|
||||
'name' => 'data[Contact][required_one][]',
|
||||
'id' => 'ContactRequiredOne',
|
||||
'required' => 'required',
|
||||
'multiple' => 'multiple'
|
||||
),
|
||||
array('option' => array('value' => '1')), 'option A', '/option',
|
||||
array('option' => array('value' => '2')), 'option B', '/option',
|
||||
'/select'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2008,6 +2008,14 @@ class FormHelper extends AppHelper {
|
|||
$tag = 'selectstart';
|
||||
}
|
||||
|
||||
if ($tag !== 'checkboxmultiplestart' &&
|
||||
!isset($attributes['required']) &&
|
||||
empty($attributes['disabled']) &&
|
||||
$this->_introspectModel($this->model(), 'validates', $this->field())
|
||||
) {
|
||||
$attributes['required'] = true;
|
||||
}
|
||||
|
||||
if (!empty($tag) || isset($template)) {
|
||||
$hasOptions = (count($options) > 0 || $showEmpty);
|
||||
// Secure the field if there are options, or its a multi select.
|
||||
|
|
Loading…
Add table
Reference in a new issue