Skip to content

Commit

Permalink
JE-400: Added choices.js to dropdowns with many options
Browse files Browse the repository at this point in the history
  • Loading branch information
tuj committed Dec 14, 2023
1 parent fece8f1 commit d816e93
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Added choices.js to dropdowns with many options.

## [1.1.0] - 2023-12-14

* Updated api source to use Leantime
Expand Down
16 changes: 16 additions & 0 deletions assets/controllers/choices_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Controller} from '@hotwired/stimulus';
import Choices from "choices.js";
import 'choices.js/src/styles/choices.scss';

/**
* Activates choices.js for each element with choices target.
*/
export default class extends Controller {
static targets = ['choices'];

connect() {
this.choicesTargets.forEach((target) => {
new Choices(target, {allowHTML: true, itemSelectText: ''});
})
}
}
7 changes: 6 additions & 1 deletion src/Controller/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function edit(Request $request, Invoice $invoice, InvoiceRepository $invo
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => [
'class' => 'form-element',
'data-choices-target' => 'choices',
'data-account-selector-target' => 'field',
],
'choices' => $paidByAccountChoices,
Expand All @@ -115,6 +116,7 @@ public function edit(Request $request, Invoice $invoice, InvoiceRepository $invo
'row_attr' => ['class' => 'form-row form-choices'],
'attr' => [
'class' => 'form-element',
'data-choices-target' => 'choices',
'data-account-selector-target' => 'field',
],
'choices' => $defaultReceiverAccountChoices,
Expand All @@ -130,7 +132,10 @@ public function edit(Request $request, Invoice $invoice, InvoiceRepository $invo
'label' => 'invoices.client',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row'],
'attr' => ['class' => 'form-element'],
'attr' => [
'class' => 'form-element',
'data-choices-target' => 'choices',
],
'help' => 'invoices.client_helptext',
'choices' => $clients,
]);
Expand Down
5 changes: 4 additions & 1 deletion src/Controller/InvoiceEntryWorklogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public function worklogs(Request $request, Invoice $invoice, InvoiceEntry $invoi
'label' => 'worklog.version',
'label_attr' => ['class' => 'label'],
'row_attr' => ['class' => 'form-row'],
'attr' => ['class' => 'form-element'],
'attr' => [
'class' => 'form-element',
'data-choices-target' => 'choices',
],
'help' => 'worklog.version_helptext',
'choices' => $project->getVersions(),
]);
Expand Down
2 changes: 1 addition & 1 deletion templates/invoice_entry/worklogs.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h1 class="page-title">{{ 'worklog.title'|trans }}</h1>

{{ form_start(form) }}
<div class="worklogs-filter-form">
<div class="worklogs-filter-form selections" {{ stimulus_controller('choices') }}>
{{ form_rest(form) }}
<button class="button m-5">{{ 'invoices.search'|trans }}</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/invoices/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h1 class="page-title">{{ invoice.name }}</h1>

{{ form_start(form) }}
<div class="grid-split">
<div class="grid-split selections" {{ stimulus_controller('choices') }}>
<div>
{{ form_row(form.name) }}
{{ form_row(form.description) }}
Expand Down
2 changes: 1 addition & 1 deletion templates/invoices/new.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h1 class="page-title">{{ 'invoices.create_new'|trans }}</h1>

{{ form_start(form) }}
<div>
<div class="selections" {{ stimulus_controller('choices') }}>
{{ form_row(form.name) }}
{{ form_row(form.description) }}
{{ form_row(form.project) }}
Expand Down

0 comments on commit d816e93

Please sign in to comment.