Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: data-request-parent demo #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions controllers/Countries.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Winter\Test\Controllers;

use Request;
use BackendMenu;
use Backend\Classes\Controller;

Expand All @@ -24,4 +25,27 @@ public function __construct()

BackendMenu::setContext('Winter.Test', 'test', 'countries');
}

public function formExtendFields($form)
{
if (!$form->isNested && $form->model instanceof \October\Test\Models\Country) {
$isActive = false;
if (Request::ajax()) {
$isActive = input('Country[is_active]', false);
} elseif ($form->model->exists) {
$isActive = $form->model->is_active;
}

if ($isActive) {
$form->addFields([
'dynamic_flags' => [
'label' => 'Active Flags (Dynamic Fileupload Field)',
'type' => 'fileupload',
'mode' => 'image',
'span' => 'right',
],
]);
}
}
}
}
4 changes: 4 additions & 0 deletions models/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class Country extends Model
'conditions' => "type = 'general.type'"
],
];
public $attachMany = [
'flags' => ['System\Models\File'],
'dynamic_flags' => ['System\Models\File'],
];

/**
* Softly implement the TranslatableModel behavior.
Expand Down
9 changes: 9 additions & 0 deletions models/country/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ fields:
field: name
type: slug

flags:
label: Flags (Static Fileupload Field)
type: fileupload
mode: image
span: full

is_active:
label: Active
comment: Check this box to hide some tabs, using depends and trigger API.
type: checkbox
span: left
default: true
attributes:
onchange: "$(this).request('form::onRefresh');"

tabs:
lazy:
Expand Down