Skip to content

Commit

Permalink
fixes #679: Removed CheckableType, ChoiceType, EntityType. Added Chec…
Browse files Browse the repository at this point in the history
…kboxType, CheckboxesType, RadiosType, DatalistType
  • Loading branch information
rudiedirkx committed Mar 21, 2022
1 parent 735c258 commit 95b602b
Show file tree
Hide file tree
Showing 22 changed files with 175 additions and 622 deletions.
7 changes: 3 additions & 4 deletions src/Kris/LaravelFormBuilder/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Kris\LaravelFormBuilder;


class Field
{
// Simple fields
const TEXT = 'text';
const TEXTAREA = 'textarea';
const SELECT = 'select';
const CHOICE = 'choice';
const CHECKBOX = 'checkbox';
const RADIO = 'radio';
const CHECKBOXES = 'checkboxes';
const RADIOS = 'radios';
const DATALIST = 'datalist';
const PASSWORD = 'password';
const HIDDEN = 'hidden';
const FILE = 'file';
Expand All @@ -31,7 +31,6 @@ class Field
const TEL = 'tel';
const NUMBER = 'number';
const RANGE = 'range';
const ENTITY = 'entity';
const FORM = 'form';
//Buttons
const BUTTON_SUBMIT = 'submit';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Kris\LaravelFormBuilder\Fields;

class CheckableType extends FormField
class CheckboxType extends FormField
{

const DEFAULT_VALUE = 1;
Expand All @@ -17,7 +17,7 @@ class CheckableType extends FormField
*/
protected function getTemplate()
{
return $this->type;
return 'checkbox';
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/Kris/LaravelFormBuilder/Fields/CheckboxesType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Kris\LaravelFormBuilder\Fields;

use Illuminate\Database\Eloquent\Collection;

class CheckboxesType extends RadiosType
{
protected function getTemplate()
{
return 'checkboxes';
}

public function setValue($value)
{
if ($value instanceof Collection) {
$value = $value->modelKeys();
}

parent::setValue($value);
}
}
173 changes: 0 additions & 173 deletions src/Kris/LaravelFormBuilder/Fields/ChoiceType.php

This file was deleted.

15 changes: 15 additions & 0 deletions src/Kris/LaravelFormBuilder/Fields/DatalistType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Kris\LaravelFormBuilder\Fields;

class DatalistType extends FormField {

protected function getTemplate() {
return 'datalist';
}

public function getAllAttributes() {
return [];
}

}
119 changes: 0 additions & 119 deletions src/Kris/LaravelFormBuilder/Fields/EntityType.php

This file was deleted.

7 changes: 1 addition & 6 deletions src/Kris/LaravelFormBuilder/Fields/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,7 @@ protected function setupValue()
}

if (($value === null || $value instanceof \Closure) && !$isChild) {
if ($this instanceof EntityType) {
$attributeName = $this->name;
} else {
$attributeName = $this->getOption('value_property', $this->name);
}

$attributeName = $this->getOption('value_property', $this->name);
$this->setValue($this->getModelValueAttribute($this->parent->getModel(), $attributeName));
} elseif (!$isChild) {
$this->hasDefault = true;
Expand Down
Loading

0 comments on commit 95b602b

Please sign in to comment.