Skip to content

Input Element Value Filter broken with 1.0.17 (works with 1.0.16) #2491

@swernerx

Description

@swernerx

Vue.js version

1.0.17

Steps to reproduce

We have developed an input component for formatted numbers (think currencies, percents) which does not work reliable anymore with the newest version. Sometimes it works, sometimes not. The issues happen when interacting with the input field e.g. changing the value in the running application. The filter has a read and write section to deal with parsing and formatting. The filter correctly sends out the changed value - but the formatted value itself does not seem to "reach" the input field. This is probably some timing / race condition issue as it works 50% of the time.

This is the markup of our component - see the v-model section about how we integrated the filter:

<input size="{{this.size ? this.size :'' }}" type="text" required="{{this.required ? this.required :'false' }}"
       maxlength="{{ this.maxlength ? this.maxlength : '' }}" pattern="^[\s0-9\.,€$£]*$"
       placeholder="{{this.placeholder ? this.placeholder :'' }}" name="{{this.name ? this.name : this.id}}"
       id="{{id}}" class="input-currency {{class}}"
       v-model="value | format-currency" v-on:blur="markTainted"/>

This is how a typical filter looks in our application:

  Vue.filter("format-currency", {
    // model -> view: formats the value when updating the input element.
    read: function read(val) {
      return formatNumber(val == null || val === "" || isNaN(val) ? 0 : val, "currency");
    },

    // view -> model: formats the value when writing to the data.
    write: function write(val) {
      return parseToNumber(val);
    }
  });

What is Expected?

It is expected that the input field always contains a formatted number when leaving/bluring the input field.

What is actually happening?

It is only formatted in about 50% of the cases. Sometimes it works. Sometimes not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions