mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Merge branch '1.3-formhelper' into 1.3-misc
This commit is contained in:
commit
aa0c7cbd7f
6 changed files with 87 additions and 52 deletions
85
cake/libs/view/helpers/form.php
Normal file → Executable file
85
cake/libs/view/helpers/form.php
Normal file → Executable 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';
|
||||
|
@ -784,10 +795,10 @@ class FormHelper extends AppHelper {
|
|||
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 @@ 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,28 +1646,25 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
}
|
||||
|
||||
$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 @@ class FormHelper extends AppHelper {
|
|||
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
|
||||
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);
|
||||
break;
|
||||
case 'NONE':
|
||||
default:
|
||||
$opt .= '';
|
||||
break;
|
||||
|
|
|
@ -37,7 +37,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
**/
|
||||
var $_optionMap = array(
|
||||
'request' => array(
|
||||
'async' => 'asyncrhronous',
|
||||
'async' => 'asynchronous',
|
||||
'data' => 'parameters',
|
||||
'before' => 'onCreate',
|
||||
'success' => 'onSuccess',
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 (&)
|
||||
*
|
||||
|
|
|
@ -227,7 +227,7 @@ class PrototypeEngineHelperTestCase extends CakeTestCase {
|
|||
));
|
||||
$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 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue