Skip to content

Commit

Permalink
Option to show a counter indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
olach committed Feb 17, 2019
1 parent 4d445fd commit 16de220
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ related:
help: Select from 3 up to 6 articles.
```
### Counter indicator
A handy indicator of the current amount of selected items can be displayed in the upper right corner with the option `counter`. This indicator is always shown when the min/max option is active, but can be disabled by setting its value to `false`.

```yaml
related:
label: Related articles
type: relationship
options: query
query:
fetch: siblings
search: true
counter: true
```

### Controller:
This field is extended with an option to use a user specified function to have even more control of the options that will be loaded. The idea is taken from the [Controlled List plugin](https://github.com/rasteiner/controlledlist).

Expand Down
3 changes: 2 additions & 1 deletion relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class RelationshipField extends CheckboxesField {
public $controller;
public $search;
public $thumbs;
public $counter;
public $min;
public $max;

Expand Down Expand Up @@ -235,7 +236,7 @@ public function validate() {
* Generates a counter element if min or max is set.
*/
public function counter() {
if (!$this->min && !$this->max || $this->readonly()) return null;
if ((!$this->min && !$this->max && !$this->counter) || $this->readonly() || $this->counter === false) return null;

$counter = new Brick('div');
$counter->addClass('field-counter marginalia text');
Expand Down

0 comments on commit 16de220

Please sign in to comment.