-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from atk4/feature/autocomplete-field
Feature/autocomplete field
- Loading branch information
Showing
38 changed files
with
625 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
require 'init.php'; | ||
require 'database.php'; | ||
|
||
// create header | ||
$layout->add(['Header', 'Database-driven form with an enjoyable layout']); | ||
|
||
// create form | ||
$form = $layout->add(new \atk4\ui\Form(['segment'])); | ||
$form->add(['Label', 'Input new country information here', 'top attached'], 'AboveFields'); | ||
|
||
$m = new \atk4\data\Model($db, 'test'); | ||
|
||
// Without AutoComplete | ||
$m->hasOne('country1', new Country()); | ||
|
||
// With AutoComplete | ||
$m->hasOne('country2', [new Country(), 'ui' => ['form' => [ | ||
'AutoComplete', | ||
'plus' => true, | ||
]]]); | ||
|
||
$form->setModel($m); | ||
|
||
$form->addField('country3', [ | ||
'AutoComplete', | ||
'model' => new Country($db), | ||
'placeholder' => 'Search for country by code, LV or UK', | ||
'search' => ['name', 'iso', 'iso3'], | ||
]); | ||
|
||
//$acc = $form->getField('country_id'); | ||
//$acc->actionRight = ['Button', 'Hello htere']; | ||
|
||
$form->onSubmit(function ($f) { | ||
return $f->model->ref('country_id')['name']; | ||
}); | ||
|
||
return; | ||
|
||
$layout->add(new \atk4\ui\FormField\AutoComplete(['placeholder' => 'Search users', 'left' => true, 'icon' => 'users'])); | ||
|
||
$layout->add(new \atk4\ui\Header(['Labels', 'size' => 2])); | ||
|
||
$layout->add(new \atk4\ui\FormField\AutoComplete(['placeholder' => 'Search users', 'label' => 'http://'])); | ||
$layout->add(new \atk4\ui\FormField\AutoComplete(['placeholder' => 'Weight', 'labelRight' => new \atk4\ui\Label(['kg', 'basic'])])); | ||
$layout->add(new \atk4\ui\FormField\AutoComplete(['label' => '$', 'labelRight' => new \atk4\ui\Label(['.00', 'basic'])])); | ||
|
||
$layout->add(new \atk4\ui\FormField\AutoComplete([ | ||
'iconLeft' => 'tags', | ||
'labelRight' => new \atk4\ui\Label(['Add Tag', 'tag']), | ||
])); | ||
|
||
// left/right corner is not supported, but here is work-around: | ||
$label = new \atk4\ui\Label(); | ||
$label->addClass('left corner'); | ||
$label->add(new \atk4\ui\Icon('asterisk')); | ||
|
||
$layout->add(new \atk4\ui\FormField\AutoComplete([ | ||
'label' => $label, | ||
]))->addClass('left corner'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Demonstrates how to use fields with form. | ||
*/ | ||
require 'init.php'; | ||
|
||
$app->add(['Header', 'Stand Alone Line']); | ||
// you can pass values to button | ||
$field = $app->add(new \atk4\ui\FormField\Line()); | ||
|
||
$field->set('hello world'); | ||
|
||
$button = $app->add(['Button', 'check value']); | ||
$button->on('click', new \atk4\ui\jsExpression('alert("field value is: "+[])', [$field->jsInput()->val()])); | ||
|
||
$app->add(['Header', 'Line in a Form']); | ||
$form = $app->add('Form'); | ||
$field = $form->addField('name', new \atk4\ui\FormField\Line()); | ||
$form->onSubmit(function ($f) { | ||
return $f->model['name']; | ||
}); | ||
|
||
$app->add(['Header', 'Multiple Form Layouts']); | ||
|
||
$form = $app->add('Form'); | ||
$tabs = $form->add('Tabs', 'AboveFields'); | ||
$form->add(['ui' => 'divider'], 'AboveFields'); | ||
|
||
$form_page = $tabs->addTab('Basic Info')->add(['FormLayout\Generic', 'form' => $form]); | ||
$form_page->addField('name', new \atk4\ui\FormField\Line()); | ||
|
||
$form_page = $tabs->addTab('Other Info')->add(['FormLayout\Generic', 'form' => $form]); | ||
$form_page->addField('age', new \atk4\ui\FormField\Line()); | ||
|
||
$form->onSubmit(function ($f) { | ||
return $f->model['name'].' has age '.$f->model['age']; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.