Skip to content

Commit 95b602b

Browse files
committed
fixes #679: Removed CheckableType, ChoiceType, EntityType. Added CheckboxType, CheckboxesType, RadiosType, DatalistType
1 parent 735c258 commit 95b602b

22 files changed

+175
-622
lines changed

src/Kris/LaravelFormBuilder/Field.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
namespace Kris\LaravelFormBuilder;
44

5-
65
class Field
76
{
87
// Simple fields
98
const TEXT = 'text';
109
const TEXTAREA = 'textarea';
1110
const SELECT = 'select';
12-
const CHOICE = 'choice';
1311
const CHECKBOX = 'checkbox';
14-
const RADIO = 'radio';
12+
const CHECKBOXES = 'checkboxes';
13+
const RADIOS = 'radios';
14+
const DATALIST = 'datalist';
1515
const PASSWORD = 'password';
1616
const HIDDEN = 'hidden';
1717
const FILE = 'file';
@@ -31,7 +31,6 @@ class Field
3131
const TEL = 'tel';
3232
const NUMBER = 'number';
3333
const RANGE = 'range';
34-
const ENTITY = 'entity';
3534
const FORM = 'form';
3635
//Buttons
3736
const BUTTON_SUBMIT = 'submit';

src/Kris/LaravelFormBuilder/Fields/CheckableType.php renamed to src/Kris/LaravelFormBuilder/Fields/CheckboxType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Kris\LaravelFormBuilder\Fields;
44

5-
class CheckableType extends FormField
5+
class CheckboxType extends FormField
66
{
77

88
const DEFAULT_VALUE = 1;
@@ -17,7 +17,7 @@ class CheckableType extends FormField
1717
*/
1818
protected function getTemplate()
1919
{
20-
return $this->type;
20+
return 'checkbox';
2121
}
2222

2323
/**
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Kris\LaravelFormBuilder\Fields;
4+
5+
use Illuminate\Database\Eloquent\Collection;
6+
7+
class CheckboxesType extends RadiosType
8+
{
9+
protected function getTemplate()
10+
{
11+
return 'checkboxes';
12+
}
13+
14+
public function setValue($value)
15+
{
16+
if ($value instanceof Collection) {
17+
$value = $value->modelKeys();
18+
}
19+
20+
parent::setValue($value);
21+
}
22+
}

src/Kris/LaravelFormBuilder/Fields/ChoiceType.php

Lines changed: 0 additions & 173 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Kris\LaravelFormBuilder\Fields;
4+
5+
class DatalistType extends FormField {
6+
7+
protected function getTemplate() {
8+
return 'datalist';
9+
}
10+
11+
public function getAllAttributes() {
12+
return [];
13+
}
14+
15+
}

src/Kris/LaravelFormBuilder/Fields/EntityType.php

Lines changed: 0 additions & 119 deletions
This file was deleted.

src/Kris/LaravelFormBuilder/Fields/FormField.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,7 @@ protected function setupValue()
142142
}
143143

144144
if (($value === null || $value instanceof \Closure) && !$isChild) {
145-
if ($this instanceof EntityType) {
146-
$attributeName = $this->name;
147-
} else {
148-
$attributeName = $this->getOption('value_property', $this->name);
149-
}
150-
145+
$attributeName = $this->getOption('value_property', $this->name);
151146
$this->setValue($this->getModelValueAttribute($this->parent->getModel(), $attributeName));
152147
} elseif (!$isChild) {
153148
$this->hasDefault = true;

0 commit comments

Comments
 (0)