diff --git a/src/Page.php b/src/Page.php index c831318..6977116 100644 --- a/src/Page.php +++ b/src/Page.php @@ -28,16 +28,20 @@ class Page extends View public string $title = ''; protected ?Layout $layout = null; + /** Used a specific js package version, ex: '1.5.0', a wildcard or leave empty for latest. */ + public string $fohnJsVersion = '^1'; + public string $jQueryVersion = '^3'; + public ?string $toastSelector = '#fohn-toast'; public string $jsBundleLocation = '/public'; /** An array of Js packages to include in Page. */ public array $jsPackages = [ 'jquery' => [ - 'url' => 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js', + 'url' => 'https://unpkg.com/jquery', ], 'fohn-js' => [ - 'url' => 'https://unpkg.com/fohn-ui@1.5.0/dist/fohn-ui.min.js', + 'url' => 'https://unpkg.com/fohn-ui', ], ]; @@ -60,6 +64,14 @@ protected function initRenderTree(): void { parent::initRenderTree(); + if ($this->fohnJsVersion) { + $this->includeJsPackage('fohn-js', 'https://unpkg.com/fohn-ui@' . $this->fohnJsVersion); + } + + if ($this->jQueryVersion) { + $this->includeJsPackage('jquery', 'https://unpkg.com/jquery@' . $this->jQueryVersion); + } + Ui::theme()::styleAs(Base::PAGE, [$this]); } diff --git a/src/Service/Atk/FormControlFactory.php b/src/Service/Atk/FormControlFactory.php index efcd4da..19bef42 100644 --- a/src/Service/Atk/FormControlFactory.php +++ b/src/Service/Atk/FormControlFactory.php @@ -220,7 +220,7 @@ protected function factorySelect(Field $field): Control $control->onSetValue(function ($value) use ($refModel) { if ($value) { $refEntity = $refModel->tryLoad($value); - if ($refEntity->isLoaded()) { + if ($refEntity) { $selectableItems[$value] = $refEntity->get($refEntity->titleField); } } @@ -236,7 +236,7 @@ protected function factorySelect(Field $field): Control $items = self::getSelectItems($refModel); if ($value && !in_array($value, array_column($items, Control\Select::KEY), true)) { $refEntity = $refModel->tryLoad($value); - if ($refEntity->isLoaded()) { + if ($refEntity) { $newItems = [Control\Select::KEY => $value, Control\Select::LABEL => $refEntity->get($refEntity->titleField)]; array_unshift($items, $newItems); }