Skip to content

Commit

Permalink
add Hidden and improve Info
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeblauw committed Sep 6, 2020
1 parent d7a40ce commit b842292
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions resources/views/components/formelements/hidden.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<input
type="hidden"
name="{{ $name }}"
id="{{ $id }}"
value="{{ old($name, $value) }}"
>
1 change: 1 addition & 0 deletions src/BlueAdminServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function boot()

// Building blocks for admin forms
Blade::component('ba-info', View\Components\FormElements\Info::class);
Blade::component('ba-hidden', View\Components\FormElements\Hidden::class);
Blade::component('ba-text', View\Components\FormElements\Textfield::class);
Blade::component('ba-textarea', View\Components\FormElements\Textarea::class);
Blade::component('ba-select', View\Components\FormElements\Select::class);
Expand Down
2 changes: 1 addition & 1 deletion src/View/Components/Formelements/HandlesBoundModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private function getFormDataBinder(): FormDataBinder
* Get the latest bound target.
* @return mixed
*/
private function getBoundTarget()
protected function getBoundTarget()
{
return $this->getFormDataBinder()->get();
}
Expand Down
17 changes: 17 additions & 0 deletions src/View/Components/Formelements/Hidden.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Ndeblauw\BlueAdmin\View\Components\FormElements;

class Hidden extends Component
{
const TEMPLATE = 'hidden';

public function __construct(
string $name,
string $value = null,
string $id = null,
$model = null
) {
parent::__construct($name, null, null, $id, null, false, null, $value);
}
}
8 changes: 7 additions & 1 deletion src/View/Components/Formelements/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ public function __construct(
string $link = null,
bool $newWindow = false,
bool $icon = false
) {
)
{
// Check if there is a belongsTo relation (name = relation.fieldname)
if (sizeof($arr=explode(".", $name, 2)) > 1) {
$value = $value ?: $this->getBoundTarget()->{$arr[0]}->{$arr[1]};
}

parent::__construct($name, $label, null, $id, $comment, null, $size, $value);

$this->link = $link ?? '';
Expand Down

0 comments on commit b842292

Please sign in to comment.