Permalink
Browse files

dont add required class on wrapper div

  • Loading branch information...
1 parent 03e5207 commit 67cc7f66da0cd543362d64584e1565fd3db32f4c @dereuromark dereuromark committed Apr 26, 2013
Showing with 22 additions and 3 deletions.
  1. +18 −1 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +4 −2 lib/Cake/View/Helper/FormHelper.php
@@ -8697,7 +8697,7 @@ public function testRequiredOnCreate() {
$this->Form->inputDefaults(array('required' => false));
$result = $this->Form->input('Contact.imrequired');
$expected = array(
- 'div' => array('class' => 'input text required'),
+ 'div' => array('class' => 'input text'),
'label' => array('for' => 'ContactImrequired'),
'Imrequired',
'/label',
@@ -8711,6 +8711,23 @@ public function testRequiredOnCreate() {
$result = $this->Form->input('Contact.imrequired', array('required' => false));
$this->assertTags($result, $expected);
+
+ $result = $this->Form->input('Contact.imrequired', array('required' => true));
+ $expected = array(
+ 'div' => array('class' => 'input text required'),
+ 'label' => array('for' => 'ContactImrequired'),
+ 'Imrequired',
+ '/label',
+ 'input' => array(
+ 'required' => 'required', 'type' => 'text', 'name' => 'data[Contact][imrequired]',
+ 'id' => 'ContactImrequired'
+ ),
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+
+ $result = $this->Form->input('Contact.imrequired', array('required' => null));
+ $this->assertTags($result, $expected);
}
/**
@@ -1271,8 +1271,10 @@ protected function _divOptions($options) {
} elseif (is_array($div)) {
$divOptions = array_merge($divOptions, $div);
}
-
- if ($this->_introspectModel($this->model(), 'validates', $this->field())) {
+ if (
+ $this->_extractOption('required', $options) !== false &&
+ $this->_introspectModel($this->model(), 'validates', $this->field())
+ ) {
$divOptions = $this->addClass($divOptions, 'required');
}
if (!isset($divOptions['tag'])) {

4 comments on commit 67cc7f6

Contributor

kimegede replied Apr 29, 2013

What is the reason not to have the "required" class on the wrapper div?

Member

ADmad replied Apr 29, 2013

@kimegede The "required" class is removed only If you specify the html5's required attribute to false for an input.

Contributor

kimegede replied Apr 29, 2013

@ADmad Sorry, should read the code also, and not only the commit message :)
Sounds good ;)

Member

ADmad replied Apr 29, 2013

@kimegede No probs, I agree the commit message could have been better 😄

Please sign in to comment.