0

this is a part of my code.

    <input type="text" v-model="formData.end_date" name="end_date" v-validate="'required'"
           v-bind:class="{'input-error' : errors.has('end_date')}">
    <span v-show="errors.has('end_date')"
          style="position: absolute; font-size: .7em ; margin-right: 1em;color: rgb(214, 48, 49);">{{errors.first('end_date') }}</span>
</div>

how can I add placeholder dynamically when error.has('end_date') return true

I try v-bind: placeholder

1
  • You can also use <input :placeholder="[[ urlPlaceholder ]]"> Commented Feb 21, 2020 at 13:35

3 Answers 3

4

Try something like this:

1) Add a computed property to your component

computed: {
   placeholder() {
      return this.errors.has('end_date') ? 'Your placeholder text' : ''
   }
}

2) Bind to your computed placeholder property with v-bind:placeholder="placeholder"

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

Comments

0

you can get that done by saying :placeholder. Is that not working for you ? In your try you have a space between v-bind:placeholder. I think you should not be having that.

Comments

0
<input
   type="text"
   v-model="FirstName"
   class="form-control"
   :placeholder="functionData"
/>

computed:{
   functionData(){
     return "Data"
  }
}

Comments

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.