coreui / coreui-free-vue-admin-template

Open source admin template based on Bootstrap 5 and Vue 3
https://coreui.io/product/free-vue-admin-template/
MIT License
3.29k stars 967 forks source link

$refs not access CFormInput Component #303

Closed viral-prm closed 4 months ago

viral-prm commented 6 months ago

Here is my form component and I'm applying custom validation to validate valid phone number format

<CFormInput type="text" class="form-control" v-model="customer.ContactPhone" ref="contactPhonea" feedbackInvalid="Please provide valid contact phone." @input="validatorContactPhone" required />

here is script

<script>
  export default {
    name: 'Customer',
  data() {
    return {
      customer: {
        ContactPhone:""
      }
    }
  },
  methods: {
    validatorContactPhone() { 

      let val = this.$refs.contactPhonea.value;
      if(!this.validPhone(val)){                
        this.$refs.contactPhonea.setCustomValidity("**some notification string ...**")        
      }
      else{
        this.$refs.contactPhonea.setCustomValidity('');
      }
      return val ? this.validPhone(val) : true
    },
  }
</script>

as in above method could not getting this.$refs.contactPhonea.value value of input

Looking for Help Thanks in advance..

github-actions[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions