2

I am using CoreUI template for VueJS version but i am not sure how to get the CInput value from this link: https://coreui.io/vue/demo/3.0-beta.1/#/forms/basic-forms,

I want to binding the input value just like this: https://v2.vuejs.org/v2/guide/forms.html#Text

Here is the code, i have used v-model but it looks like it is unable to work:

<template>
    <div>
        <p style="white-space: preline;">{{message}}</p>
        <CForm>
              <CInput
                v-model="message"
                label="Input is valid"
                valid-feedback="Input is valid."
                invalid-feedback="Please provide at least 4 characters."
                value="Valid value"
                :is-valid="validator"
              />
              <CInput
                label="Input is invalid"
                valid-feedback="Thank you :)"
                invalid-feedback="Please provide at least 4 characters."
                :is-valid="validator"
              />
            </CForm>
    </div>
</template>
<script>
export default {
    methods: {
        validator(val) {
            return val ? val.length >= 4 : false
        }
    }
}
</script>

1 Answer 1

5

v-model isn't available with CInput component. According to their docs, you can use the events (update:value, input and change) to update your component data. Example:

<template>
<div>
    <p style="white-space: preline;">{{message}}</p>
    <CForm>
          <CInput
            label="Input is valid"
            valid-feedback="Input is valid."
            invalid-feedback="Please provide at least 4 characters."
            :value="message"
            @input="message = $event.target.value"
            :is-valid="validator"
          />
          <CInput
            label="Input is invalid"
            valid-feedback="Thank you :)"
            invalid-feedback="Please provide at least 4 characters."
            :is-valid="validator"
          />
        </CForm>
</div>
</template>
<script>
export default {
    data () {
      return {
        message: "",
      }
    },
    methods: {
        validator(val) {
            return val ? val.length >= 4 : false
        }
    }
}
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

@input="message = $event.target.value", in my case target was returning itself the value of the input. I don't know if it's a thing about newer versions or it's already a bug in your example. Thanks anyway for the tip, I find CoreUI for Vue docs very poor in this case
Well I used v-model for input in my code and works fine. Please review and edit. TNX

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.