Element: [Question] How to set default value of select Component and Still be able to change its value from other option?

Created on 2 Nov 2017  ·  4Comments  ·  Source: ElemeFE/element

I haveselect component, one for selecting layout and depending upon the value selected, I give different option in Subsequent select components.

 <el-form-item label="Page Layout">
   <el-select  v-model="form.Layout" @change="layoutChange()" placeholder="Please select Layout">
      <el-option
         v-for="item in form.layoutsOption"
         :key="item.value"
         :label="item.label"
         :value="item.value">
      </el-option>
   </el-select>
</el-form-item>

   <div v-for='(n,index) in partialsList'>
      <el-form-item :label="n ">
         <el-select v-model="form.parent_id[n]" placeholder="Please select " >
            <el-option  v-for="item in AllData[index]" 
               :key="item.value"
               :label="item.label"
               :value="item"
               :disabled="item.disabled">
            </el-option>
         </el-select>
      </el-form-item>
   </div>

Here :
form.Layout is string,
form.layoutsOption is array getting data from JSON .
partialList is a array which contains multiple suboption to be selected in our selected Layout.
form.parent_id is used to store the selected value in array(Because there are multiple Suboption.
AllData is a array which upon Layout selection sets its option .

Now, let me tell you the flow as how things happen.
image

Step 1:
image
image

Step 2:
image

OR
image

Step 3:
image

Finally,
image

first a select component asking to select a layout. Then as soon as layout is selected , multiple sub select component appear and these are the option of that layout which are required for my further process.

So, my required is such that i need those sub option selection select component to have a inherit default value in every layout i select. If not default then the first option in that selection to be selected automatically.
Lets just say that i need default option to be selected implicitly. By which if user want default he will just save without having to select default again and aganin.

The way i did, doesnt allow them to change value,
image

they remain same even if a explicitly want to change the option.

P.S
A lengthy question, but i would appreciate the help, and tell me know if you are not able to understand the requirement of my question.
Thank you.

Most helpful comment

Oh com 'on man!!!
Help me out here.

All 4 comments

Hello, this issue has been closed because it does not conform to our issue requirements. Please submit issues with issue-generator. More info can be found in #3693.

Oh com 'on man!!!
Help me out here.

anybody has any solution of this, instead of using value-key, can we do it?

anybody has any solution of this, instead of using value-key, can we do it?

set option you need into value

Was this page helpful?
0 / 5 - 0 ratings