Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '1.3-formhelper' into 1.3-misc

  • Loading branch information...
commit aa0c7cbd7f796e809f7d62b58f09e5476a2bd6a5 2 parents 078b845 + 4e038e5
@markstory markstory authored
View
85 cake/libs/view/helpers/form.php 100644 → 100755
@@ -1,6 +1,4 @@
<?php
-/* SVN FILE: $Id$ */
-
/**
* Automatic generation of HTML FORMs from given data.
*
@@ -9,20 +7,16 @@
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.view.helpers
* @since CakePHP(tm) v 0.10.0.1076
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
@@ -79,15 +73,26 @@ class FormHelper extends AppHelper {
var $requestType = null;
/**
+ * Persistent default options used by input(). Set by FormHelper::create().
+ *
+ * @var array
+ * @access protected
+ */
+ var $_inputDefaults = array();
+
+/**
* Returns an HTML FORM element.
*
- * Options:
+ * #### Options:
*
* - 'type' Form method defaults to POST
* - 'action' The Action the form submits to. Can be a string or array,
* - 'url' The url the form submits to. Can be a string or a url array,
* - 'default' Allows for the creation of Ajax forms.
* - 'onsubmit' Used in conjunction with 'default' to create ajax forms.
+ * - 'inputDefaults' set the default $options for FormHelper::input(). Any options that would
+ * be set when using FormHelper::input() can be set here. Options set with `inputDefaults`
+ * can be overridden when calling input()
*
* @access public
* @param string $model The model object which the form is being defined for
@@ -179,8 +184,11 @@ function create($model = null, $options = array()) {
'type' => ($created && empty($options['action'])) ? 'put' : 'post',
'action' => null,
'url' => null,
- 'default' => true),
+ 'default' => true,
+ 'inputDefaults' => array()),
$options);
+ $this->_inputDefaults = $options['inputDefaults'];
+ unset($options['inputDefaults']);
if (empty($options['url']) || is_array($options['url'])) {
if (empty($options['url']['controller'])) {
@@ -607,8 +615,11 @@ function input($fieldName, $options = array()) {
$this->setEntity($fieldName);
$entity = join('.', $view->entity());
- $defaults = array('before' => null, 'between' => null, 'after' => null);
- $options = array_merge($defaults, $options);
+ $options = array_merge(
+ array('before' => null, 'between' => null, 'after' => null),
+ $this->_inputDefaults,
+ $options
+ );
if (!isset($options['type'])) {
$options['type'] = 'text';
@@ -784,10 +795,10 @@ function input($fieldName, $options = array()) {
unset($options['dateFormat']);
}
- $type = $options['type'];
- $before = $options['before'];
+ $type = $options['type'];
+ $before = $options['before'];
$between = $options['between'];
- $after = $options['after'];
+ $after = $options['after'];
unset($options['type'], $options['before'], $options['between'], $options['after']);
switch ($type) {
@@ -1536,8 +1547,8 @@ function meridian($fieldName, $selected = null, $attributes = array(), $showEmpt
* - 'separator' The contents of the string between select elements. Defaults to '-'
*
* @param string $fieldName Prefix name for the SELECT element
- * @param string $dateFormat DMY, MDY, YMD or NONE.
- * @param string $timeFormat 12, 24, NONE
+ * @param string $dateFormat DMY, MDY, YMD.
+ * @param string $timeFormat 12, 24.
* @param string $selected Option which is selected.
* @param string $attributes array of Attributes
* @param bool $showEmpty Whether or not to show an empty default value.
@@ -1573,7 +1584,7 @@ function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected
$days[1] = $selected;
}
- if ($timeFormat != 'NONE' && !empty($timeFormat)) {
+ if (!empty($timeFormat)) {
$time = explode(':', $days[1]);
$check = str_replace(':', '', $days[1]);
@@ -1635,28 +1646,25 @@ function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected
}
}
- $opt = '';
-
- if ($dateFormat != 'NONE') {
- $selects = array();
- foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
- switch ($char) {
- case 'Y':
- $selects[] = $this->year(
- $fieldName, $minYear, $maxYear, $year, $selectYearAttr, $showEmpty
- );
- break;
- case 'M':
- $selectMonthAttr['monthNames'] = $monthNames;
- $selects[] = $this->month($fieldName, $month, $selectMonthAttr, $showEmpty);
- break;
- case 'D':
- $selects[] = $this->day($fieldName, $day, $selectDayAttr, $showEmpty);
- break;
- }
+ $selects = array();
+ foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
+ switch ($char) {
+ case 'Y':
+ $selects[] = $this->year(
+ $fieldName, $minYear, $maxYear, $year, $selectYearAttr, $showEmpty
+ );
+ break;
+ case 'M':
+ $selectMonthAttr['monthNames'] = $monthNames;
+ $selects[] = $this->month($fieldName, $month, $selectMonthAttr, $showEmpty);
+ break;
+ case 'D':
+ $selects[] = $this->day($fieldName, $day, $selectDayAttr, $showEmpty);
+ break;
}
- $opt = implode($separator, $selects);
}
+ $opt = implode($separator, $selects);
+
if (!empty($interval) && $interval > 1 && !empty($min)) {
$min = round($min * (1 / $interval)) * $interval;
}
@@ -1671,7 +1679,6 @@ function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);
break;
- case 'NONE':
default:
$opt .= '';
break;
View
2  cake/libs/view/helpers/prototype_engine.php
@@ -37,7 +37,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
**/
var $_optionMap = array(
'request' => array(
- 'async' => 'asyncrhronous',
+ 'async' => 'asynchronous',
'data' => 'parameters',
'before' => 'onCreate',
'success' => 'onSuccess',
View
3  cake/tests/cases/libs/model/model_integration.test.php
@@ -2,7 +2,7 @@
/* SVN FILE: $Id: model.test.php 8225 2009-07-08 03:25:30Z mark_story $ */
/**
- * ModelDeleteTest file
+ * ModelIntegrationTest file
*
* Long description for file
*
@@ -26,7 +26,6 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
require_once dirname(__FILE__) . DS . 'model.test.php';
-require_once dirname(__FILE__) . DS . 'model_integration.test.php';
/**
* ModelIntegrationTest
View
1  cake/tests/cases/libs/model/model_validation.test.php
@@ -26,7 +26,6 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
require_once dirname(__FILE__) . DS . 'model.test.php';
-require_once dirname(__FILE__) . DS . 'model_validation.test.php';
/**
* ModelValidationTest
View
35 cake/tests/cases/libs/view/helpers/form.test.php
@@ -1,6 +1,4 @@
<?php
-/* SVN FILE: $Id$ */
-
/**
* FormHelperTest file
*
@@ -9,20 +7,16 @@
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
- * Copyright 2006-2008, Cake Software Foundation, Inc.
+ * Copyright 2006-2009, Cake Software Foundation, Inc.
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
- * @filesource
- * @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
+ * @copyright Copyright 2006-2009, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
* @since CakePHP(tm) v 1.2.0.4206
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
@@ -4718,6 +4712,31 @@ function testFormCreate() {
}
/**
+ * test that inputDefaults are stored and used.
+ *
+ * @return void
+ **/
+ function testCreateWithInputDefaults() {
+ $this->Form->create('User', array(
+ 'inputDefaults' => array('div' => false, 'label' => false)
+ ));
+ $result = $this->Form->input('username');
+ $expected = array(
+ 'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername', 'value' => '')
+ );
+ $this->assertTags($result, $expected);
+
+ $result = $this->Form->input('username', array('div' => true, 'label' => 'username'));
+ $expected = array(
+ 'div' => array('class' => 'input text'),
+ 'label' => array('for' => 'UserUsername'), 'username', '/label',
+ 'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername', 'value' => ''),
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+ }
+
+/**
* Test base form url when url param is passed with multiple parameters (&)
*
*/
View
13 cake/tests/cases/libs/view/helpers/prototype_engine.test.php
@@ -227,7 +227,7 @@ function testRequest() {
));
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {method:"post", onComplete:doSuccess, onFailure:handleError, parameters:$("element").serialize()});';
$this->assertEqual($result, $expected);
-
+
$result = $this->Proto->request('/people/edit/1', array(
'method' => 'post',
'before' => 'doBefore();',
@@ -237,6 +237,17 @@ function testRequest() {
));
$expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {method:"post", onComplete:function (transport) {doComplete();}, onCreate:function (transport) {doBefore();}, onFailure:function (response, jsonHeader) {handleError();}, onSuccess:function (response, jsonHeader) {doSuccess();}});';
$this->assertEqual($result, $expected);
+
+ $result = $this->Proto->request('/people/edit/1', array(
+ 'async' => false,
+ 'method' => 'post',
+ 'before' => 'doBefore();',
+ 'success' => 'doSuccess();',
+ 'complete' => 'doComplete();',
+ 'error' => 'handleError();',
+ ));
+ $expected = 'var jsRequest = new Ajax.Request("/people/edit/1", {asynchronous:false, method:"post", onComplete:function (transport) {doComplete();}, onCreate:function (transport) {doBefore();}, onFailure:function (response, jsonHeader) {handleError();}, onSuccess:function (response, jsonHeader) {doSuccess();}});';
+ $this->assertEqual($result, $expected);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.