Last active
March 23, 2022 03:19
-
-
Save Fusseldieb/0e2bd6af4579a37cb1dabdd8866a80b5 to your computer and use it in GitHub Desktop.
Revisions
-
Fusseldieb revised this gist
Nov 28, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ <!-- Access it with: <select2 v-model="field.value" :options="field.options" :tags="true"></select2> A object exists with following structure: field: { value: "", -
Fusseldieb revised this gist
Nov 28, 2018 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,6 @@ export default { props: ["options", "value", "ajax", "tags"], mounted: function() { var vm = this; let options = []; options.push({ id: "", -
Fusseldieb revised this gist
Nov 28, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ <!-- Access it with: <select2 v-model="fields.value" :options="fields.options" :tags="true"></select2> A object exists with following structure: field: { value: "", options: [ -
Fusseldieb revised this gist
Nov 28, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ <!-- Access it with: <select2 v-model="fields.value" :options="fields.options" :tags="true"></select2> A object exist with following structure: field: { value: "", options: [ -
Fusseldieb revised this gist
Nov 28, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Access it with: <select2 v-model="fields.value" :options="fields.options" :tags="true"></select2> A object fields exist with following structure: field: { value: "", options: [ { id: "0", text: "No" }, -
Fusseldieb revised this gist
Nov 28, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ fields: { } The "tags" parameter is there to allow the user to write its own text and select it. In the "options" array, there are "id" and "text". The "ajax" object is also supported. Just add :ajax="field.ajax" to the HTML tag and put your ajax call inside "field" as "ajax". Import this component in your view or whatever with: -
Fusseldieb revised this gist
Nov 28, 2018 . 1 changed file with 25 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,16 +23,13 @@ import Select2 from "@/components/Select2.vue"; (or where the file is) EDIT: Now the options are reactive. If you use a computed property to translate the options (or similar), this Select2 template will automatically update all options and select the same option again, with the new text Strings. EDIT2: [BUGFIX] Fixed v-model being destroyed. Now the options are reloaded without destroying and reloading Select2. --> <template> <select :value="value" style="width: 100%"></select> </template> <script> @@ -44,9 +41,19 @@ export default { props: ["options", "value", "ajax", "tags"], mounted: function() { var vm = this; // console.log(this.options); let options = []; options.push({ id: "", text: "Choose...", // Supports vue-i18n, just put 'this.$t('select2.choose')' here disabled: true, selected: true }); options = options.concat(this.options); $(this.$el) // init select2 .select2({ ajax: this.ajax, tags: this.tags, data: options }) .val(this.value) .trigger("change") // emit event on change. @@ -61,15 +68,18 @@ export default { .val(value) .trigger("change"); }, options: function(newoptions) { let options = []; options.push({ id: "", text: "Choose...", // Supports vue-i18n, just put 'this.$t('select2.choose')' here disabled: true, selected: true }); options = options.concat(newoptions); $(this.$el) .empty() .select2({ data: options }); } }, destroyed: function() { -
Fusseldieb revised this gist
Nov 22, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import Select2 from "@/components/Select2.vue"; (or where the file is) ... Basically an "improved" example of https://vuejs.org/v2/examples/select2.html EDIT: Now the options are reactive. If you use a computed property to translate the options (or similar), this Select2 template will automatically update all options and select the same option again, with the new text Strings. (It does that by destroying, and then recreating the Select2 instance in the nextTick. -
Fusseldieb revised this gist
Nov 22, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,8 +21,8 @@ import Select2 from "@/components/Select2.vue"; (or where the file is) ... Basically an "improved" example of https://vuejs.org/v2/examples/select2.html EDIT: Now supports "options live reloading". If you use a computed property to translate the options (or similar), this Select2 template will automatically update all options and select the same option again, with the new text Strings. (It does that by destroying, and then recreating the Select2 instance in the nextTick. This reinitialization is unnoticeable to the human eye.) -
Fusseldieb revised this gist
Nov 22, 2018 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,11 +20,17 @@ import Select2 from "@/components/Select2.vue"; (or where the file is) ... Basically an "improved" example of https://vuejs.org/v2/examples/select2.html EDIT: Now supports "options live reloading". If you use vue-i18n (or something else) and use a computed property to translate the options (or similar), this Select2 template will automatically update all options and select the same option again, with the new language. (It does that by destroying, and then recreating the Select2 instance in the nextTick. This reinitialization is unnoticeable to the human eye.) --> <template> <select :value="value" style="width: 100%"> <option value="" selected disabled>Choose...</option> <option v-for="(val) in options" :key="val.id">{{val.text}}</option> </select> </template> -
Fusseldieb revised this gist
Nov 22, 2018 . 1 changed file with 8 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,8 @@ import Select2 from "@/components/Select2.vue"; (or where the file is) <template> <select :value="value" style="width: 100%"> <option value="" selected disabled>Auswählen...</option> <option v-for="(val) in options" :key="val.id">{{val.text}}</option> </select> </template> @@ -53,13 +54,16 @@ export default { $(this.$el) .val(value) .trigger("change"); }, options: function(options) { // update options $(this.$el) .off() .select2("destroy"); this.$nextTick(function() { $(this.$el).select2(); }); } }, destroyed: function() { -
Fusseldieb revised this gist
Nov 8, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,6 +18,8 @@ The "ajax" object is also supported. Just add :ajax="field.ajax" to the HTML tag Import this component in your view or whatever with: import Select2 from "@/components/Select2.vue"; (or where the file is) ... Basically an "improved" example of https://vuejs.org/v2/examples/select2.html --> <template> -
Fusseldieb revised this gist
Nov 8, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ A object fields exist with following structure: fields: { value: "", options: [ { id: "0", text: "No" }, { id: "5", text: "5 mm" }, { id: "10", text: "10 mm" } ] @@ -22,7 +22,7 @@ import Select2 from "@/components/Select2.vue"; (or where the file is) <template> <select :value="value" style="width: 100%"> <option value="" selected disabled>Choose...</option> </select> </template> -
Fusseldieb revised this gist
Nov 8, 2018 . 1 changed file with 33 additions and 30 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,35 +1,29 @@ <!-- Access it with: <select2 v-model="fields.value" :options="fields.options" :tags="true"></select2> A object fields exist with following structure: fields: { value: "", options: [ { id: "0", text: "Nein" }, { id: "5", text: "5 mm" }, { id: "10", text: "10 mm" } ] } The "tags" parameter is there to allow the user to write its own text and select it. In the "options" array, there are "id" and "text", but if no "id" is specified, "text" will be used on both. See ternary in template below. The "ajax" object is also supported. Just add :ajax="field.ajax" to the HTML tag and put your ajax call inside "field" as "ajax". Import this component in your view or whatever with: import Select2 from "@/components/Select2.vue"; (or where the file is) --> <template> <select :value="value" style="width: 100%"> <option value="" selected disabled>Auswählen...</option> </select> </template> <script> @@ -38,29 +32,38 @@ import select2 from "select2"; export default { name: "Select2", props: ["options", "value", "ajax", "tags"], mounted: function() { var vm = this; $(this.$el) // init select2 .select2({ data: this.options, ajax: this.ajax, tags: this.tags }) .val(this.value) .trigger("change") // emit event on change. .on("change", function() { vm.$emit("input", this.value); }); }, watch: { value: function(value) { // update value $(this.$el) .val(value) .trigger("change"); console.log("CHNG", value); }, options: function(options) { // update options $(this.$el) .empty() .select2({ data: options }); } }, destroyed: function() { $(this.$el) .off() .select2("destroy"); } }; </script> -
Fusseldieb revised this gist
Nov 6, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,9 +58,9 @@ export default { .val(value) .trigger("change"); }, // options: function(options) { // console.log(options); // } } }; </script> -
Fusseldieb revised this gist
Nov 6, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ The "ajax" object is also supported. Just add :ajax="field.ajax" to the HTML tag Import this component in your view or whatever with: import Select2 from "@/components/select2-custom.vue"; (or wherever the file is) --> -
Fusseldieb revised this gist
Nov 6, 2018 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ <!-- Access it with: <select2 v-model="field.value" :options="field.options" :tags="true"></select2> A object "field" exist with following structure: field: { value: "", -
Fusseldieb revised this gist
Nov 6, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ A object "field" exist with following structure: field: { value: "", options: [ { value: "0", text: "No" }, { value: "5", text: "5 mm" }, { value: "10", text: "10 mm" } ] @@ -23,7 +23,7 @@ import Select2 from "@/components/select2-custom.vue"; (or where the file is) <template> <select :value="value" style="width: 100%"> <option value="" selected disabled>Choose...</option> <option v-if="!options">{{ value }}</option> <option v-for="option in options" :value="option.value ? option.value : option.text"> {{ option.text }} -
Fusseldieb revised this gist
Nov 6, 2018 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ <!-- Access it with: <select2 v-model="field.value" :options="field.options" :tags="true"></select2> A object "field" exist with following structure: field: { value: "", options: [ { value: "0", text: "Nein" }, @@ -13,6 +13,8 @@ fields: { The "tags" parameter is there to allow the user to write its own text and select it. In the "options" array, there are "value" and "text", but if no "value" is specified, "text" will be used on both. See ternary in template below. The "ajax" object is also supported. Just add :ajax="field.ajax" to the HTML tag and put your ajax call inside "field" as "ajax". Import this component in your view or whatever with: import Select2 from "@/components/select2-custom.vue"; (or where the file is) @@ -35,7 +37,7 @@ import select2 from "select2"; export default { name: "Select2", props: ["value", "options", "tags", "ajax"], mounted: function() { const vm = this; -
Fusseldieb revised this gist
Nov 6, 2018 . No changes.There are no files selected for viewing
-
Fusseldieb revised this gist
Nov 6, 2018 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,24 @@ <!-- Access it with: <select2 v-model="fields.value" :options="fields.options" :tags="true"></select2> A object fields exist with following structure: fields: { value: "", options: [ { value: "0", text: "Nein" }, { value: "5", text: "5 mm" }, { value: "10", text: "10 mm" } ] } The "tags" parameter is there to allow the user to write its own text and select it. In the "options" array, there are "value" and "text", but if no "value" is specified, "text" will be used on both. See ternary in template below. Import this component in your view or whatever with: import Select2 from "@/components/select2-custom.vue"; (or where the file is) --> <template> <select :value="value" style="width: 100%"> <option value="" selected disabled>Auswählen...</option> -
Fusseldieb revised this gist
Nov 6, 2018 . No changes.There are no files selected for viewing
-
Fusseldieb revised this gist
Nov 6, 2018 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,8 +30,6 @@ export default { }, watch: { value: function(value) { $(this.$el) .val(value) .trigger("change"); -
Fusseldieb revised this gist
Nov 6, 2018 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,6 @@ export default { // selectOnClose: true, ajax: vm.ajax }) .on("change", function() { vm.$emit("input", vm.$el.value); }); @@ -39,7 +38,6 @@ export default { }, options: function(options) { console.log(options); } } }; -
Fusseldieb created this gist
Nov 6, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ <template> <select :value="value" style="width: 100%"> <option value="" selected disabled>Auswählen...</option> <option v-if="!options">{{ value }}</option> <option v-for="option in options" :value="option.value ? option.value : option.text"> {{ option.text }} </option> </select> </template> <script> import $ from "jquery"; import select2 from "select2"; export default { name: "Select2", props: ["value", "options", "tags", "format", "ajax"], mounted: function() { const vm = this; $(vm.$el) .select2({ tags: vm.tags, // selectOnClose: true, ajax: vm.ajax }) // .trigger("change") .on("change", function() { vm.$emit("input", vm.$el.value); }); }, watch: { value: function(value) { // update value $(this.$el) .val(value) .trigger("change"); }, options: function(options) { console.log(options); console.log("Options Debug Test"); } } }; </script>