0

My uppercase directive below works fine with <input>:

<input
  type="text"
  v-model="foo"
  v-uppercase
>

But for some reason, it doesn't work with <b-form-input>:

<b-form-input
  type="text"
  v-model="foo"
  v-uppercase
></b-form-input>

The uppercase directive:

  directives: {
    uppercase: {
      update: function (el) {
        el.value = el.value.toUpperCase();
      }
    }
  }

Is there something wrong in my code ? How should I fix it ?

DevonDahon
  • 7,460
  • 6
  • 69
  • 114

1 Answers1

3

If you want just change to uppercase easiest way is use style:

.uppercase{
    text-transform: uppercase;
}

Also use filter can another choice:

    filters: {
        uppercase: function(v) {
            return v.toUpperCase();
        }
    }

And if you want use directive as you use v-model got some problems so you can combine it with style solution:

Vue.directive("uppercase", {
    bind(el, binding, vnode) {
        el.style.textTransform = 'uppercase';
    },
    update(el, binding, vnode) {
        el.style.textTransform = 'uppercase';
    }
});

Here is simple codepen for directive for show all solutions

Mohsen
  • 4,049
  • 1
  • 31
  • 31