Skip to content

Commit

Permalink
Merge pull request #284 from dakota/inline-forms
Browse files Browse the repository at this point in the history
Inline forms
  • Loading branch information
ADmad authored Sep 30, 2019
2 parents 958a5dd + 2f60e40 commit 6d57476
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 54 deletions.
7 changes: 0 additions & 7 deletions src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,6 @@ public function create($model = null, array $options = [])
'templates' => [],
];

if ($options['align'] === 'inline') {
trigger_error(
'Support for inline forms is currently broken. Patches to fix it are welcome.',
E_USER_WARNING
);
}

return parent::create($model, $this->_formAlignment($options));
}

Expand Down
131 changes: 84 additions & 47 deletions tests/TestCase/View/Helper/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,6 @@ public function testRadio()
*/
public function testInlineRadioControl()
{
$this->markTestSkipped('Inline forms are broken right now');

$this->Form->create($this->article);

$result = $this->Form->control('published', [
Expand All @@ -816,38 +814,48 @@ public function testInlineRadioControl()
'options' => ['Yes', 'No']
]);
$expected = [
['div' => ['class' => 'form-group radio']],
['label' => true],
['div' => ['class' => 'form-group radio', 'role' => 'group', 'aria-labelledby' => 'published-group-label']],
['label' => ['id' => 'published-group-label', 'class' => 'd-block']],
'Published',
'/label',
[
'input' => [
'type' => 'hidden',
'name' => 'published',
'value' => ''
]
],
['div' => ['class' => 'form-check form-check-inline']],
['input' => [
'type' => 'hidden',
'name' => 'published',
'value' => ''
]],
[
'input' => [
'type' => 'radio',
'name' => 'published',
'value' => 0,
'id' => 'published-0',
'class' => 'form-check-input',
]
],
['label' => [
'class' => 'radio-inline',
'class' => 'form-check-label',
'for' => 'published-0'
]],
['input' => [
'type' => 'radio',
'name' => 'published',
'value' => 0,
'id' => 'published-0'
]],
'Yes',
'/label',
'/div',
['div' => ['class' => 'form-check form-check-inline']],
[
'input' => [
'type' => 'radio',
'name' => 'published',
'value' => 1,
'id' => 'published-1',
'class' => 'form-check-input',
]
],
['label' => [
'class' => 'radio-inline',
'class' => 'form-check-label',
'for' => 'published-1'
]],
['input' => [
'type' => 'radio',
'name' => 'published',
'value' => 1,
'id' => 'published-1'
]],
'No',
'/label',
'/div',
Expand Down Expand Up @@ -961,7 +969,7 @@ public function testFormCreateWithTemplatesFile()
*/
public function testInlineFormCreate()
{
$result = $this->Form->create($this->article, ['class' => 'form-inline']);
$result = $this->Form->create($this->article, ['align' => 'inline']);
$expected = [
'form' => [
'method' => 'post',
Expand All @@ -981,6 +989,39 @@ public function testInlineFormCreate()
$this->assertHtml($expected, $result);
}

/**
* testTooltipInline method
*
* @return void
*/
public function testTooltipInline()
{
$this->Form->create($this->article, ['align' => 'inline']);

$result = $this->Form->control('title', ['tooltip' => 'Some important additional notes.']);
$expected = [
'div' => ['class' => 'form-group text required'],
'label' => ['class' => 'sr-only', 'for' => 'title'],
'Title ',
'span' => [
'data-toggle' => 'tooltip',
'title' => 'Some important additional notes.',
'class' => 'fas fa-info-circle'
],
'/span',
'/label',
'input' => [
'type' => 'text',
'name' => 'title',
'id' => 'title',
'class' => 'form-control',
'required' => 'required'
],
'/div'
];
$this->assertHtml($expected, $result);
}

/**
* testHorizontalFormCreate method
*
Expand Down Expand Up @@ -3209,7 +3250,7 @@ public function testDefaultAlignRadioPerOptionConfiguration()
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'form-check-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand Down Expand Up @@ -3280,7 +3321,7 @@ public function testDefaultAlignRadioPerOptionConfigurationInline()
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'form-check-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand Down Expand Up @@ -3345,7 +3386,7 @@ public function testDefaultAlignRadioPerOptionConfigurationInlineNestedInput()
'/label',
'/div',
['div' => ['class' => 'form-check form-check-inline']],
['label' => ['class' => 'form-check-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
['input' => [
'class' => 'custominputclass',
'type' => 'radio',
Expand Down Expand Up @@ -3670,7 +3711,7 @@ public function testHorizontalAlignRadioControlPerOptionConfiguration()
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'form-check-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand Down Expand Up @@ -3750,7 +3791,7 @@ public function testHorizontalAlignRadioControlPerOptionConfigurationInline()
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'form-check-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand Down Expand Up @@ -3824,7 +3865,7 @@ public function testHorizontalAlignRadioControlPerOptionConfigurationInlineNeste
'/label',
'/div',
['div' => ['class' => 'form-check form-check-inline']],
['label' => ['class' => 'form-check-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
['input' => [
'class' => 'custominputclass',
'type' => 'radio',
Expand Down Expand Up @@ -3960,7 +4001,7 @@ public function testInlineAlignRadioControlWithPerOptionConfiguration()
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'form-check-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand Down Expand Up @@ -4083,7 +4124,7 @@ public function testInlineAlignRadioControlWithPerOptionConfigurationNestedInput
'/label',
'/div',
['div' => ['class' => 'form-check form-check-inline']],
['label' => ['class' => 'form-check-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
['input' => [
'class' => 'custominputclass',
'type' => 'radio',
Expand Down Expand Up @@ -6542,11 +6583,9 @@ public function testHorizontalAlignSubmit()

public function testInlineAlignSubmit()
{
$this->withErrorReporting(0, function () {
$this->Form->create($this->article, [
'align' => 'inline'
]);
});
$this->Form->create($this->article, [
'align' => 'inline'
]);

$result = $this->Form->submit('Submit');
$expected = [
Expand Down Expand Up @@ -6939,7 +6978,7 @@ public function testDefaultAlignCustomRadioControlPerOptionConfiguration()
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'custom-control-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand Down Expand Up @@ -7011,7 +7050,7 @@ public function testDefaultAlignCustomRadioControlPerOptionConfigurationInline()
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'custom-control-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand Down Expand Up @@ -7211,7 +7250,7 @@ public function testHorizontalAlignCustomRadioControlPerOptionConfiguration()
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'custom-control-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand Down Expand Up @@ -7292,7 +7331,7 @@ public function testHorizontalAlignCustomRadioControlPerOptionConfigurationInlin
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'custom-control-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand All @@ -7304,11 +7343,9 @@ public function testHorizontalAlignCustomRadioControlPerOptionConfigurationInlin

public function testInlineAlignCustomRadioControl()
{
$this->withErrorReporting(0, function () {
$this->Form->create($this->article, [
'align' => 'inline'
]);
});
$this->Form->create($this->article, [
'align' => 'inline'
]);

$result = $this->Form->control('users', [
'type' => 'radio',
Expand Down Expand Up @@ -7423,7 +7460,7 @@ public function testInlineAlignCustomRadioControlWithPerOptionConfiguration()
'id' => 'users-12',
'value' => 12
]],
['label' => ['class' => 'custom-control-label', 'for' => 'users-12']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-12']],
'option 3',
'/label',
'/div',
Expand Down

0 comments on commit 6d57476

Please sign in to comment.