diff --git a/resources/js/selectize-one.js b/resources/js/selectize-one.js index a45d578..7deb265 100644 --- a/resources/js/selectize-one.js +++ b/resources/js/selectize-one.js @@ -1,11 +1,12 @@ /** - * selectize one select widget. Substitute the actual id of the widget for `{{widget_id}}`. + * selectize one select widget. Substitute the actual id of the widget for `{{widget_id}}`, + * and the current value for {{widget_value}}. */ $('#{{widget_id}}').selectize({ valueField: 'id', labelField: 'name', searchField: 'name', - options: [], + hideSelected: false, create: false, load: function(query, callback) { @@ -25,4 +26,4 @@ $('#{{widget_id}}').selectize({ } }); } -}); +})[0].selectize.setValue({{widget_value}}, true); diff --git a/src/adl/to_selmer_templates.clj b/src/adl/to_selmer_templates.clj index ff1b30e..443b3a0 100644 --- a/src/adl/to_selmer_templates.clj +++ b/src/adl/to_selmer_templates.clj @@ -266,8 +266,14 @@ farkey "}}' {% ifequal record." (-> property :attrs :name) - " option." farkey "%}selected{% endifequal %}>" - (s/join " " (map #(str "{{option." (:name (:attrs %)) "}}") fs-distinct)) + " option." farkey "%}selected='selected'{% endifequal %}>" + (s/join " " (map + #(str + "{{option." + (:name (:attrs %)) + (if (= (-> % :attrs :type) "entity") "_expanded") + "}}") + fs-distinct)) "{% endfor %}")])) @@ -616,7 +622,8 @@ (> magnitude 2) (embed-script-fragment "resources/js/selectize-one.js" - [["{{widget_id}}" (-> property :attrs :name)]] + [["{{widget_id}}" (-> property :attrs :name)] + ["{{widget_value}}" (str "{{record." (-> property :attrs :name) "}}")]] )))) (children-with-tag entity :property #(= (-> % :attrs :type) "entity"))) (if