Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: mdb-select binding and defaulting.

dnadeveloper priority asked 5 years ago


I’m having a difficult time using the mdb-select in a production environment that requires binding and reselecting items from stored values. In the past, I would do something like this: class="form-control fc-web h-55"> {{reportSubjectTarget.text}} The select would roll out my options in reportSubjectOptions and bind to the place I store the selected value reportBag.reportDefinitions[activeReportDef].reportSubjectSelections If I changed the selected value in the data, the list would show it. I’m not seeing how to accomplish this with mdb-select. How would I do it? Essentially, when I load my data model, I need all saved selections to be reflected in the select controls.


dnadeveloper priority commented 5 years ago

This was intended for the Vue tec. area. Didn't see a way to correct the post.


Magdalena Dembna staff answered 5 years ago


The snippet below shows that if you toggle selected key for one of the options the select's dropdown will update and change this option. What won't update is the list of items - to do that you would need to use some kind of watcher and forced update (as the change is deep). Let me know if this code snippet was helpful. Kind regards, Magdalena

<mdb-container> 
     <mdb-row>
          <mdb-col sm="6">
            <mdb-select multiple search selectAll :options="multiOptions" label="Example label" />
          </mdb-col>
          <mdb-col sm="3">
            <p class="mb-0" v-for="(option, index) in multiOptions" :key="index" :class="option.selected && 'text-success'">{{option.text}}</p>
          </mdb-col>
        </mdb-row>
        <mdb-btn @click="multiOptions[3].selected = true">ok</mdb-btn>
    </mdb-container>
import { mdbSelect, mdbRow, mdbCol, mdbContainer } from 'mdbvue';

export default {
  name: 'SelectPage',
  components: {
    mdbSelect,
    mdbRow,
    mdbCol,
    mdbContainer
  },
  data() {
    return {
      multiOptions: [
        { text: 'Choose your options', value: null, disabled: true },
        { text: 'Option nr 1', value: 'Option 1' }, 
        { text: 'Option nr 2', value: 'Option 2' }, 
        { text: 'Option nr 3', value: 'Option 3' }, 
        { text: 'Option nr 4', value: 'Option 4' }, 
        { text: 'Option nr 5', value: 'Option 5' }
      ]
    }
  },

};


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB jQuery
  • MDB Version: 4.8.9
  • Device: desktop
  • Browser: chrome
  • OS: windows
  • Provided sample code: No
  • Provided link: No