Skip to content

Commit

Permalink
Merge pull request #551 from atk4/feature/lookup-field
Browse files Browse the repository at this point in the history
Feature/lookup field
  • Loading branch information
romaninsh committed Oct 8, 2018
2 parents 3aa52ef + 70702b4 commit 72cbf4d
Show file tree
Hide file tree
Showing 10 changed files with 639 additions and 7 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,27 @@ $table->resizableColumn(function($j, $w){

// For Grid or CRUD:
$crud->table->resizableColumn
```

We also introducing a somewhat experemental "Lookup" field. It is identical to AutoComplete and can work as a stand-in
replacement, but supports "filters". For now we are looking for ways to make this field more compact before it becomes
part of AutoComplete.

``` php

$form = $app->add(new \atk4\ui\Form(['segment']));
$form->add(['Label', 'Add city', 'top attached'], 'AboveFields');

$l = $form->addField('city',['Lookup']);

// will restraint possible city value in droddown base on country and/or language.
$l->addFilter('country', 'Country');
$l->addFilter('language', 'Lang');

//make sure country and language belong to your model.
$l->setModel(new City($db));
```


**Closed issues:**

Expand Down
25 changes: 25 additions & 0 deletions demos/autocomplete.php
Expand Up @@ -69,3 +69,28 @@
$a->setModel(new Country($p->app->db));
});
$app->add(['Button', 'Open autocomplete on a Modal window'])->on('click', $modal->show());

$app->add(['Header', 'New Lookup field']);

$form = $app->add(new \atk4\ui\Form(['segment']));
$form->add(['Label', 'Input new country information here', 'top attached'], 'AboveFields');

$c = new Country($db);
$c->addExpression('letter1', 'concat("Ends with ", substring([name], -1))');

$form->addField('country1', [
'Lookup',
'model' => new Country($db),
'hint' => 'Lookup field is just like AutoComplete, supports all the same options.',
'placeholder' => 'Search for country by code, LV or UK',
'search' => ['name', 'iso', 'iso3'],
]);

$lookup = $form->addField('country2', [
'Lookup',
'model' => $c,
'hint' => 'However one or few "filtering" options can be added narrowing down the final result set',
'placeholder' => 'Search for country by code, LV or UK',
'search' => ['name', 'iso', 'iso3'],
]);
$lookup->addFilter('letter1');
2 changes: 1 addition & 1 deletion demos/init.php
Expand Up @@ -33,7 +33,7 @@
$form->addItem('Data Integration', ['form2']);
$form->addItem('Form Multi-column layout', ['form3']);
$form->addItem(['Integration with Columns'], ['form5']);
$form->addItem(['AutoComplete Field'], ['autocomplete']);
$form->addItem(['AutoComplete Field', 'icon'=>'yellow star'], ['autocomplete']);
$form->addItem(['Value Selectors'], ['form6']);
$form->addItem(['Conditional Fields'], ['jscondform']);

Expand Down
21 changes: 21 additions & 0 deletions docs/autocomplete.rst
Expand Up @@ -55,3 +55,24 @@ You can do much more with AutoComplete field by passing dropdown settings::
]
])->setModel(new Country($db));


Lookup Field
============

In 1.6 we have introduced Lookup field, which is identical to AutoComplete but additionally allows
use of Filters::


$form = $app->add(new \atk4\ui\Form(['segment']));
$form->add(['Label', 'Add city', 'top attached'], 'AboveFields');

$l = $form->addField('city',['Lookup']);

// will restraint possible city value in droddown base on country and/or language.
$l->addFilter('country', 'Country');
$l->addFilter('language', 'Lang');

//make sure country and language belong to your model.
$l->setModel(new City($db));

Possibly this feature will be introduced into "AutoComplete" class.
7 changes: 7 additions & 0 deletions src/FormField/Generic.php
Expand Up @@ -20,6 +20,8 @@ class Generic extends View
*/
public $field;

public $fieldClass = '';

/**
* @var bool - Whether you need this field to be rendered wrap in a form layout or as his.
*/
Expand Down Expand Up @@ -118,4 +120,9 @@ public function onChange($expr)
}
$this->on('change', '#'.$this->id.'_input', $expr);
}

public function getFieldClass()
{
return $this->fieldClass;
}
}

0 comments on commit 72cbf4d

Please sign in to comment.