Skip to content
Permalink
Browse files

Allowing a html tag's attribute to be omitted from ouput by setting i…

…ts value to null or false. Closes #316
  • Loading branch information...
ADmad committed Feb 7, 2010
1 parent 843d3c7 commit 8c1c0e63c0b9641d5ebd61f4d210c161b2f001af
Showing with 91 additions and 73 deletions.
  1. +8 −4 cake/libs/view/helper.php
  2. +83 −69 cake/tests/cases/libs/view/helpers/form.test.php
@@ -302,10 +302,12 @@ function clean($output) {
* 'escape' is a special option in that it controls the conversion of
* attributes to their html-entity encoded equivalents. Set to false to disable html-encoding.
*
* If value for any option key is set to `null` or `false`, that option will be excluded from output.
*
* @param array $options Array of options.
* @param array $exclude Array of options to be excluded, the options here will not be part of the return.
* @param string $insertBefore String to be inserted before options.
* @param string $insertAfter String to be inserted ater options.
* @param string $insertAfter String to be inserted after options.
* @return string Composed attributes.
* @access public
*/
@@ -322,7 +324,9 @@ function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $inser
$attributes = array();
foreach ($keys as $index => $key) {
$attributes[] = $this->__formatAttribute($key, $values[$index], $escape);
if ($values[$index] !== false && $values[$index] !== null) {
$attributes[] = $this->__formatAttribute($key, $values[$index], $escape);
}
}
$out = implode(' ', $attributes);
} else {
@@ -711,7 +715,7 @@ function value($options = array(), $field = null, $key = 'value') {
}
/**
* Sets the defaults for an input tag. Will set the
* Sets the defaults for an input tag. Will set the
* name, value, and id attributes for an array of html attributes. Will also
* add a 'form-error' class if the field contains validation errors.
*
@@ -737,7 +741,7 @@ function _initInputField($field, $options = array()) {
/**
* Adds the given class to the element options
*
* @param array $options Array options/attributes to add a class to
* @param array $options Array options/attributes to add a class to
* @param string $class The classname being added.
* @param string $key the key to use for class.
* @return array Array of options with $key set.
Oops, something went wrong.

0 comments on commit 8c1c0e6

Please sign in to comment.
You can’t perform that action at this time.