Skip to content

Commit 1653623

Browse files
authored
fix lookup (#1661)
1 parent 7fbe829 commit 1653623

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

demos/_includes/DemoLookup.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ protected function initQuickNewRecord()
4242
$vp->set(function ($page) {
4343
$form = \Atk4\Ui\Form::addTo($page);
4444

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

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

4949
$form->onSubmit(function (\Atk4\Ui\Form $form) {
5050
// Prevent from saving

demos/form-control/lookup.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@
3939
]);
4040

4141
$form->onSubmit(function (Form $form) {
42-
$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');
42+
$str = $form->model->ref('country1')->get(Country::hinting()->fieldName()->name);
43+
$str .= '; ';
44+
$str .= $form->model->ref('country2')->get(Country::hinting()->fieldName()->name);
45+
$str .= '; ';
46+
$str .= (new Country($form->getApp()->db))->tryLoad($form->model->get('country3'))->get(Country::hinting()->fieldName()->name);
47+
4348
$view = new \Atk4\Ui\Message('Select:'); // need in behat test.
4449
$view->invokeInit();
4550
$view->text->addParagraph($str);

src/Form/Control/Lookup.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ protected function initQuickNewRecord()
270270
$vp->set(function ($page) {
271271
$form = \Atk4\Ui\Form::addTo($page);
272272

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

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

277277
$form->onSubmit(function (\Atk4\Ui\Form $form) {
278278
$form->model->save();

tests-behat/lookup.feature

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@ Feature: Lookup
1414
Then I press menu button "Add Category" using class "atk-grid-menu"
1515
Then I select value "Beverages" in lookup "category"
1616
Then I press Modal button "Save"
17-
Then Toast display should contains text 'Beverages'
17+
Then Toast display should contains text "Beverages"
18+
19+
Scenario: Testing lookup add
20+
Given I am on "form-control/lookup.php"
21+
Then I press button "Add New"
22+
When I fill in "atk_fp_country__name" with "New country"
23+
When I fill in "atk_fp_country__iso" with "AA"
24+
When I fill in "atk_fp_country__iso3" with "AAA"
25+
When I fill in "atk_fp_country__numcode" with "88"
26+
When I fill in "atk_fp_country__phonecode" with "8"
27+
Then I press Modal button "Save"
28+
Then Toast display should contains text "Form submit!"

0 commit comments

Comments
 (0)