Skip to content

Commit efa3414

Browse files
authored
Merge pull request #8 from marcomilon/feature/add-support-for-dropdown-menu
Add support for dropdown menu
2 parents 5cc030b + be283a2 commit efa3414

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

src/form/Builder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ class Builder
1212
'text' => '/views/input-text.php',
1313
'email' => '/views/input-text.php',
1414
'password' => '/views/input-text.php',
15-
'textarea' => '/views/textarea.php'
15+
'textarea' => '/views/textarea.php',
16+
'dropdown' => '/views/dropdown.php'
1617
];
1718

1819
private $optionalParameters = [
1920
'label',
2021
'id',
21-
'placeholder',
22+
'placeholder',
23+
'options',
2224
'repeat',
2325
'blockId'
2426
];

src/form/schemas/input.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343
},
4444
"value": {
4545
"description": "The value attribute of the input",
46-
"type": "string"
46+
"type": "string"
47+
},
48+
"options": {
49+
"description": "An array of key, value attribute of the input",
50+
"type": "object"
4751
},
4852
"repeat": {
4953
"description": "Boolean value to make the input repetable",

src/form/views/dropdown.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
// Template variables
3+
$for = isset($id) ? " for=\"$id\"" : "";
4+
$id = isset($id) ? " id=\"$id\"" : "";
5+
$placeholder = isset($placeholder) ? " placeholder=\"$placeholder\"" : "";
6+
?>
7+
<div class="form-group">
8+
<label<?= $for ?>><?= $label ?></label>
9+
<select class="form-control" name="<?= $name ?>"<?= $placeholder . $id ?>>
10+
<?php foreach($options as $key => $value): ?>
11+
<option values="<?= $key ?>"><?= $value ?></option>
12+
<?php endforeach; ?>
13+
</select>
14+
</div>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"inputs": [
3+
{
4+
"name": "city",
5+
"type": "dropdown",
6+
"options": {
7+
"1": "Lima",
8+
"2": "Arequipa"
9+
}
10+
}
11+
]
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="form-group">
2+
<label>City</label>
3+
<select class="form-control" name="city">
4+
<option values="1">Lima</option>
5+
<option values="2">Arequipa</option>
6+
</select>
7+
</div>

tests/unit/micro/form/Builder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,14 @@ public function testCustomTextarea()
192192
private function flatString($str) {
193193
return preg_replace('/\s*/m', '', $str);
194194
}
195+
196+
public function testInputSimpleDropDown()
197+
{
198+
$microForm = file_get_contents(dirname(__FILE__) . '/../../../data/simple/dropdown-menu-tpl.json');
199+
$expectedRendering = dirname(__FILE__) . '/../../../data/simple/dropdown-menu.html';
200+
201+
$builder = new \micro\form\Builder();
202+
$form = $builder->render($microForm);
203+
$this->string($form)->isEqualToContentsOfFile($expectedRendering);
204+
}
195205
}

0 commit comments

Comments
 (0)