Skip to content
Merged
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
4 changes: 2 additions & 2 deletions demos/_includes/DemoLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ protected function initQuickNewRecord()
$vp->set(function ($page) {
$form = \Atk4\Ui\Form::addTo($page);

$model = clone $this->model;
$entity = $this->model->createEntity();

$form->setModel($model->onlyFields($this->plus['fields'] ?? []));
$form->setModel($entity->onlyFields($this->plus['fields'] ?? []));

$form->onSubmit(function (\Atk4\Ui\Form $form) {
// Prevent from saving
Expand Down
7 changes: 6 additions & 1 deletion demos/form-control/lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
]);

$form->onSubmit(function (Form $form) {
$str = $form->model->ref('country1')->get('name') . ' ' . $form->model->ref('country2')->get('name') . ' ' . (new Country($form->getApp()->db))->tryLoad($form->model->get('country3'))->get('name');
$str = $form->model->ref('country1')->get(Country::hinting()->fieldName()->name);
$str .= '; ';
$str .= $form->model->ref('country2')->get(Country::hinting()->fieldName()->name);
$str .= '; ';
$str .= (new Country($form->getApp()->db))->tryLoad($form->model->get('country3'))->get(Country::hinting()->fieldName()->name);

$view = new \Atk4\Ui\Message('Select:'); // need in behat test.
$view->invokeInit();
$view->text->addParagraph($str);
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Control/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ protected function initQuickNewRecord()
$vp->set(function ($page) {
$form = \Atk4\Ui\Form::addTo($page);

$model = clone $this->model;
$entity = $this->model->createEntity();

$form->setModel($model->onlyFields($this->plus['fields'] ?? []));
$form->setModel($entity->onlyFields($this->plus['fields'] ?? []));

$form->onSubmit(function (\Atk4\Ui\Form $form) {
$form->model->save();
Expand Down
13 changes: 12 additions & 1 deletion tests-behat/lookup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ Feature: Lookup
Then I press menu button "Add Category" using class "atk-grid-menu"
Then I select value "Beverages" in lookup "category"
Then I press Modal button "Save"
Then Toast display should contains text 'Beverages'
Then Toast display should contains text "Beverages"

Scenario: Testing lookup add
Given I am on "form-control/lookup.php"
Then I press button "Add New"
When I fill in "atk_fp_country__name" with "New country"
When I fill in "atk_fp_country__iso" with "AA"
When I fill in "atk_fp_country__iso3" with "AAA"
When I fill in "atk_fp_country__numcode" with "88"
When I fill in "atk_fp_country__phonecode" with "8"
Then I press Modal button "Save"
Then Toast display should contains text "Form submit!"