2

Sorry for the beginner question, I am new to Vue.js. I am using CoreUI. Documentation/Tutorials on CoreUI+Vue are scarce.

I am using the <CForm> tag and here I have a <CSelect> tag.

<CForm @submit="test" ref="form">
  <CSelect
    label="Pick a name"
    :options="['test', 'test1', 'test2']"
    v-model="testy"
  />
  
  <CButton type="submit" size="sm" color="primary"> Submit</CButton>
</CForm>

JavaScript:

methods: {
  test(e) {
    console.log("test");
    debugger;
    e.preventDefault();
  }
}

When my breakpoint is hit and I inspect this.testy it will not return the value of the select box but instead this:

I was under the impression that putting v-model on my CSelect will expose my select box under this.* and I could somehow easily get the value (?!).

For context this is rendered in the DOM:

<select id="uid-wvkj98yh6gp" class="form-control">
  <option data-key="0" value="test"> test </option>
  <option data-key="1" value="test1"> test1 </option>
  <option data-key="2" value="test2"> test2 </option>
</select>

My question: inside my test(e) method, how can I gather the current selected value of my select box?

1 Answer 1

3

In the <CSelect> API docs, it lists the value prop:

value

The value of select input. Set .sync modifier to track prop changes.

It seems they don't use v-model as expected and you probably also got an error about the value prop being incorrect.

Change your select to:

<CSelect
  label="Pick a name"
  :options="['test', 'test1', 'test2']"
  :value.sync="testy"
/>

This way you use the .sync modifier the way the guide directs.

Sign up to request clarification or add additional context in comments.

2 Comments

Awesome, that did work. As a total noob with VueJS it wasn't a good idea to jump straight into CoreUI, because I don't know which behaviour is VueJS and which is CoreUI related - and also the CoreUI docs are quite alien to me. Thanks though..!
You're welcome. Yeah it seems they do things a little differently. You won't find many libraries opting for .sync over v-model like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.