Skip to content
Permalink
Browse files

Remove FormHelper:create() options relating to ajax forms.

  • Loading branch information...
ADmad committed Mar 9, 2014
1 parent 218de22 commit 7fe1db5da01ea32e5ed45ee3a702057a6f3a1ad5
Showing with 1 addition and 55 deletions.
  1. +1 −13 src/View/Helper/FormHelper.php
  2. +0 −42 tests/TestCase/View/Helper/FormHelperTest.php
@@ -253,10 +253,6 @@ protected function _isRequiredField($validationRules) {
* don't need to change the controller from the current request's controller.
* - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url'
* you should leave 'action' undefined.
* - `default` Allows for the creation of Ajax forms. Set this to false to prevent the default event handler.
* Will create an onsubmit attribute if it doesn't not exist. If it does, default action suppression
* will be appended.
* - `onsubmit` Used in conjunction with 'default' to create ajax forms.
* - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
* - `context` Additional options for the context class. For example the EntityContext accepts a 'table'
* option that allows you to set the specific Table class the form should be based on.
@@ -284,7 +280,6 @@ public function create($model = null, $options = []) {
'type' => $isCreate ? 'post' : 'put',
'action' => null,
'url' => null,
'default' => true,
'encoding' => strtolower(Configure::read('App.encoding')),
];
@@ -313,17 +308,10 @@ public function create($model = null, $options = []) {
}
$this->requestType = strtolower($options['type']);
if (!$options['default']) {
if (!isset($options['onsubmit'])) {
$options['onsubmit'] = '';
}
$htmlAttributes['onsubmit'] = $options['onsubmit'] . 'event.returnValue = false; return false;';
}
if (!empty($options['encoding'])) {
$htmlAttributes['accept-charset'] = $options['encoding'];
}
unset($options['type'], $options['encoding'], $options['default']);
unset($options['type'], $options['encoding']);
$htmlAttributes = array_merge($options, $htmlAttributes);
@@ -384,48 +384,6 @@ public function testCreateUpdateForm() {
$this->assertTags($result, $expected);
}
/**
* Test the onsubmit option for create()
*
* @return void
*/
public function testCreateOnSubmit() {
$this->Form->request->data = [];
$this->Form->request['controller'] = 'articles';
$result = $this->Form->create($this->article, ['url' => ['action' => 'index', 'param'], 'default' => false]);
$expected = array(
'form' => array(
'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/articles/index/param',
'accept-charset' => 'utf-8'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
$this->Form->request->data = [];
$this->Form->request['controller'] = 'articles';
$result = $this->Form->create($this->article, array(
'url' => array('action' => 'index', 'param'),
'default' => false,
'onsubmit' => 'someFunction();'
));
$expected = array(
'form' => array(
'method' => 'post',
'onsubmit' => 'someFunction();event.returnValue = false; return false;',
'action' => '/articles/index/param',
'accept-charset' => 'utf-8'
),
'div' => array('style' => 'display:none;'),
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
'/div'
);
$this->assertTags($result, $expected);
}
/**
* test create() with automatic url generation
*

0 comments on commit 7fe1db5

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