From de3762e2db02f876bdd032c9e1afe716d3c25dde Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 19 Apr 2018 17:23:09 +0200 Subject: ReferentialVehicleJourneys: Fix line drop-down placeholder After adding the `initvalue` data attribute, the placeholder was no longer rendered. Fix this by: 1. Removing all elements from the collection to ensure that boolean options don't get added by default to the select (https://github.com/plataformatec/simple_form/blob/84e4465/lib/simple_form/inputs/collection_input.rb#L36-L41) 2. Not setting an `initSelection` on the Select2 config if the initial selection fields are empty. This finally gets the placeholder to display correctly again. Refs #5889 --- app/assets/javascripts/select2.coffee | 3 ++- app/views/referential_vehicle_journeys/_filters.html.slim | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/select2.coffee b/app/assets/javascripts/select2.coffee index f34b5d5ce..2ff5e198e 100644 --- a/app/assets/javascripts/select2.coffee +++ b/app/assets/javascripts/select2.coffee @@ -28,7 +28,8 @@ bind_select2_ajax = (el, cfg = {}) -> escapeMarkup: (markup) -> markup - if _this.data('initvalue') + initValue = _this.data('initvalue') + if initValue && initValue.id && initValue.text cfg["initSelection"] = (item, callback) -> callback(_this.data('initvalue')) bind_select2(el, cfg) diff --git a/app/views/referential_vehicle_journeys/_filters.html.slim b/app/views/referential_vehicle_journeys/_filters.html.slim index 8cd17ca0a..49e6317f7 100644 --- a/app/views/referential_vehicle_journeys/_filters.html.slim +++ b/app/views/referential_vehicle_journeys/_filters.html.slim @@ -23,6 +23,7 @@ .form-inline.filter_menu = f.input :route_line_id_eq, as: :select, + collection: [], include_blank: t(".all"), input_html: { \ data: { \ -- cgit v1.2.3