Skip to content

Commit ef04213

Browse files
committed
add html field in form.
1 parent 1a19db6 commit ef04213

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

src/Form.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* @method Field\Divide divide()
5555
* @method Field\Password password($column, $label = '')
5656
* @method Field\Decimal decimal($column, $label = '')
57+
* @method Field\Html html($html)
5758
*/
5859
class Form
5960
{
@@ -871,6 +872,7 @@ public static function registerBuiltinFields()
871872
'timeRange' => \Encore\Admin\Form\Field\TimeRange::class,
872873
'url' => \Encore\Admin\Form\Field\Url::class,
873874
'year' => \Encore\Admin\Form\Field\Year::class,
875+
'html' => \Encore\Admin\Form\Field\Html::class,
874876
];
875877

876878
foreach ($map as $abstract => $class) {

src/Form/Field/Html.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Encore\Admin\Form\Field;
4+
5+
use Encore\Admin\Form\Field;
6+
7+
class Html extends Field
8+
{
9+
/**
10+
* Htmlable.
11+
*
12+
* @var string
13+
*/
14+
protected $html = '';
15+
16+
/**
17+
* Create a new Html instance.
18+
*
19+
* @param mixed $html
20+
*/
21+
public function __construct($html)
22+
{
23+
$this->html = $html;
24+
}
25+
26+
/**
27+
* Render html field.
28+
*
29+
* @return string
30+
*/
31+
public function render()
32+
{
33+
return <<<EOT
34+
<div class="form-group">
35+
<label class="col-sm-2 control-label"></label>
36+
<div class="col-sm-6">
37+
$this->html
38+
</div>
39+
</div>
40+
EOT;
41+
42+
}
43+
}

tests/UserFormTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public function testCreatePage()
3434
->seeElement('span[class=help-block] i[class*=fa-image]')
3535
->seeInElement('span[class=help-block]', '上传头像')
3636
->seeElement("select[name='tags[]'][multiple=multiple]")
37-
->dontSeeElement('a[class*=item_delete]');
37+
->dontSeeElement('a[class*=item_delete]')
38+
->seeInElement('a[html-field]', 'html...');
3839
}
3940

4041
public function testSubmitForm()

tests/controllers/UserController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ protected function form()
146146

147147
$form->display('created_at', 'Created At');
148148
$form->display('updated_at', 'Updated At');
149+
150+
$form->html('<a html-field>html...</a>');
149151
});
150152
}
151153
}

0 commit comments

Comments
 (0)