Merge branch '1.3-formhelper' into 1.3-misc

This commit is contained in:
mark_story 2009-10-16 22:03:07 -04:00
commit aa0c7cbd7f
6 changed files with 87 additions and 52 deletions

47
cake/libs/view/helpers/form.php Normal file → Executable file
View file

@ -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
*/
@ -78,16 +72,27 @@ 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 @@ class FormHelper extends AppHelper {
'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 @@ class FormHelper extends AppHelper {
$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';
@ -1536,8 +1547,8 @@ class FormHelper extends AppHelper {
* - '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 @@ class FormHelper extends AppHelper {
$days[1] = $selected;
}
if ($timeFormat != 'NONE' && !empty($timeFormat)) {
if (!empty($timeFormat)) {
$time = explode(':', $days[1]);
$check = str_replace(':', '', $days[1]);
@ -1635,9 +1646,6 @@ class FormHelper extends AppHelper {
}
}
$opt = '';
if ($dateFormat != 'NONE') {
$selects = array();
foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) {
switch ($char) {
@ -1656,7 +1664,7 @@ class FormHelper extends AppHelper {
}
}
$opt = implode($separator, $selects);
}
if (!empty($interval) && $interval > 1 && !empty($min)) {
$min = round($min * (1 / $interval)) * $interval;
}
@ -1671,7 +1679,6 @@ class FormHelper extends AppHelper {
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);
break;
case 'NONE':
default:
$opt .= '';
break;

View file

@ -37,7 +37,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
**/
var $_optionMap = array(
'request' => array(
'async' => 'asyncrhronous',
'async' => 'asynchronous',
'data' => 'parameters',
'before' => 'onCreate',
'success' => 'onSuccess',

View file

@ -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 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_validation.test.php';
/**
* ModelValidationTest

View file

@ -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')) {
@ -4717,6 +4711,31 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected);
}
/**
* 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 file

@ -237,6 +237,17 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
));
$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);
}
/**