Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!--
  Forked from:
  https://quasar.dev/vue-components/select#Example--Filtering-and-adding-to-menu
-->
<div id="q-app">
  <div class="q-pa-md">
    <q-badge color="secondary" multi-line>
      <!-- Show state of q-select variables for debugging: -->
      selectModel: {{ selectModel }}
      <br />
      selectOptions: {{ selectOptions }}
      <br />
      selectFilterOptions: {{ selectFilterOptions }}
      <br />
    </q-badge>
 <!--*******************************************************************************-->
 <!-- q-select objectives: Allow user to define new option values, and add -->
 <!-- them to the model AND menu, same as in the forked q-select example in -->
 <!--https://quasar.dev/vue-components/select#Example--Filtering-and-adding-to-menu -->
 <!-- Note: q-select selection is "multiple" -->
 <!--*******************************************************************************-->
 <!-- The error: If the user enters a NEW value in the input field, that value is -->
 <!-- not added to the model and not to the menu (although the rest of filtering  -->
 <!-- and selecting from menu works correctly) -->
 <!-- Console log shows the following errors in the abovesituation: -->
 <!-- The parameter 'val' in the call to the @new-value function is UNDEFINED!!! -->
 <!-- "[Vue warn]: Error in v-on handler: -->
 <!-- 'TypeError: Cannot read property 'length' of undefined'"" -->
 <!-- The solution: Remove the "()" in @new-value="createSelectValue()"!!! -->
 <!-- See https://forum.quasar-framework.org/topic/4696/solved-error-in-q-select-with-filtering-and-adding-to-menu-aka-to-use-or-not-to-use -->
 <!--*******************************************************************************-->
     <q-select
          square
          bg-color="teal-1"
          standout="bg-teal-3 text-white"
          filled
          v-model="selectModel"
          :options="selectFilterOptions"
          @filter="selectFilterFunction"
          @new-value="createSelectValue"
          :multiple="true"
          label="Enter option values - new values get added to the dropdown menu and model"
          stack-label
          use-chips
          options-selected-class="text-primary"
          options-dense
          use-input
          input-debounce="0"
          bottom-slots
          style="width: 600px"
       >
       <template v-slot:append>
         <q-icon name="search"/>
         <q-icon
             name="cancel"
             @click.stop="selectModel = []"
             class="cursor-pointer"
             color="primary"
          />
       </template>
       </template>
    <template v-slot:selected-item="scope">
      <!-- Show scope for debugging: -->
      <!-- scope: {{scope}} -->
      <q-chip
          removable
          dense
          @remove="scope.removeAtIndex(scope.index)"
          :tabindex="scope.tabindex"
          color="primary"
          text-color="white"
          class="q-ma-none"
        >
        {{ scope.opt }}
      </q-chip>
    </template>
    <template v-slot:option="scope">
      <q-item
         v-bind="scope.itemProps"
         v-on="scope.itemEvents"
      >
      <q-item-section>
         <q-item-label
           v-html="scope.opt"
          />
       </q-item-section>
      </q-item>
    </template>
    </q-select>
</div>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                // const stringOptions = [ 'Google', 'Facebook', 'Twitter', 'Apple', 'Oracle' ]

new Vue({
  el: '#q-app',
  data () {
    return {
      selectOptions: [], 
      selectFilterOptions: [], 
      selectModel: [], 
      showHintSelect: false,
    }
  },

  methods: {
    //-----------------------------------------------------------------------------------------------
    initializeSelectOptionsAndSelectFilterOptions() {
      // Initialize select options and filter options for testing
      console.log("In initializeSelectOptionsAndSelectFilterOptions");
      // 3 variants for array handlling - all variants work
      // this.selectOptions.push("xl"); // Variant a for testing
      // this.selectOptions.push("xs"); // Variant a for testing
      // this.selectOptions.push("lg"); // Variant a for testing
      this.selectOptions = [ "xl", "xs", "lg" ]; // Variant b for testing
      // this.selectOptions = []; // Variant c for testing
      
      console.log("selectOptions: ", this.selectOptions);
      
      this.selectFilterOptions.push("xl"); // Variant a for testing
      this.selectFilterOptions.push("xs"); // Variant a for testing
      this.selectFilterOptions.push("lg"); // Variant a for testing
      // this.selectFilterOptions = [ "xl", "xs", "lg" ]; // Variant b for testing
      // this.selectFilterOptions = []; // Variant c for testing
      
      console.log("selectFilterOptions: ", this.selectFilterOptions);
    },
    //-----------------------------------------------------------------------------------------------
    createSelectValue(val, done) {
      console.log("In createSelectValue - val: ", val); // Undefined in case of the error!
      if (val.length > 1) {
        if (!this.selectOptions.includes(val)) { 
          // Add value as new option to QSelect dropdown menu
          this.selectOptions.push(val);
        }
       done(val, "toggle");
      }
    },
    //-----------------------------------------------------------------------------------------------
    selectFilterFunction(
      val,
      update
    ) {
      update(() => {
        console.log("In selectFilterFunction für update - val: ", val); // val is (filter) text in input field
       
        if (val === "") {
          this.selectFilterOptions = this.selectOptions; // Array assignment, following Quasar sample code       
          // Variant with array cloning through ES6 spread operator on array - does NOT solve the error:
          // this.selectFilterOptions = [...this.selectOptions];
          console.log("selectOptions: ", this.selectOptions);
          console.log("selectFilterOptions: ", this.selectFilterOptions);
        } else {
          const needle = val.toLowerCase();
          this.selectFilterOptions = this.selectOptions.filter( 
            // Array filter with arrow function, following Quasar sample code
            v => v.toLowerCase().indexOf(needle) > -1  );
          
          console.log("selectFilterOptions: ", this.selectFilterOptions);
        }
      });
    },
  //-------------------------------------------------------------------------------------------------------
  }, // /methods:
    mounted: async function() {
          this.selectModel.push("xl"); // Variant a for testing
          this.selectModel.push("xs"); // Variant a for testing
          this.selectModel.push("lg"); // Variant a for testing
       // this.selectModel = [ "xl", "xs", "lg" ]; // Variant b for testing
       // this.selectModel = []; // Variant c for testing
          this.initializeSelectOptionsAndSelectFilterOptions(); // Initialize select options and filter options
    } // mounted:
})
              
            
!
999px

Console