Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed setting "required" attribute for file input. Closes #4124

In general fixed the issue where enabling SECURE_SKIP for a field
skipped "required" attribute check altogether. Instead now "required"
is set to false for hidden fields by default.
  • Loading branch information...
commit aa60b8791a213acc1a3ffbc5c6d41e5c12e74727 1 parent ba1eb7e
@ADmad ADmad authored
View
16 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -8184,6 +8184,22 @@ public function testFormInputRequiredDetection() {
'/div'
);
$this->assertTags($result, $expected);
+
+ $result = $this->Form->input('Contact.iamrequiredalways', array('type' => 'file'));
+ $expected = array(
+ 'div' => array('class' => 'input file required'),
+ 'label' => array('for' => 'ContactIamrequiredalways'),
+ 'Iamrequiredalways',
+ '/label',
+ 'input' => array(
+ 'type' => 'file',
+ 'name' => 'data[Contact][iamrequiredalways]',
+ 'id' => 'ContactIamrequiredalways',
+ 'required' => 'required'
+ ),
+ '/div'
+ );
+ $this->assertTags($result, $expected);
}
/**
View
27 lib/Cake/View/Helper/FormHelper.php
@@ -1625,17 +1625,16 @@ public function textarea($fieldName, $options = array()) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::hidden
*/
public function hidden($fieldName, $options = array()) {
- $secure = true;
+ $options += array('required' => false, 'secure' => true);
+
+ $secure = $options['secure'];
+ unset($options['secure']);
- if (isset($options['secure'])) {
- $secure = $options['secure'];
- unset($options['secure']);
- }
$options = $this->_initInputField($fieldName, array_merge(
$options, array('secure' => self::SECURE_SKIP)
));
- if ($secure && $secure !== self::SECURE_SKIP) {
+ if ($secure === true) {
$this->_secure(true, null, '' . $options['value']);
}
@@ -2012,12 +2011,8 @@ public function select($fieldName, $options = array(), $attributes = array()) {
$tag = 'selectstart';
}
- if ($tag !== 'checkboxmultiplestart' &&
- !isset($attributes['required']) &&
- empty($attributes['disabled']) &&
- $this->_introspectModel($this->model(), 'validates', $this->field())
- ) {
- $attributes['required'] = true;
+ if ($tag === 'checkboxmultiplestart') {
+ unset($attributes['required']);
}
if (!empty($tag) || isset($template)) {
@@ -2847,15 +2842,21 @@ protected function _initInputField($field, $options = array()) {
if ($this->tagIsInvalid() !== false) {
$result = $this->addClass($result, 'form-error');
}
- if (!empty($result['disabled']) || $secure === self::SECURE_SKIP) {
+
+ if (!empty($result['disabled'])) {
return $result;
}
+
if (!isset($result['required']) &&
$this->_introspectModel($this->model(), 'validates', $this->field())
) {
$result['required'] = true;
}
+ if ($secure === self::SECURE_SKIP) {
+ return $result;
+ }
+
$this->_secure($secure, $this->_secureFieldName($options));
return $result;
}
Please sign in to comment.
Something went wrong with that request. Please try again.