Skip to content

Add note about binding null to <option/> being a breaking change #7

Open
@phil294

Description

In attribute coercion, the docs explain that binding an attribute as null will effectively remove it now.

This introduces a new breaking change when handling native forms which, I think, should be documented more clearly:

<form>
  <select name="mySelect" v-model="mySelect">
    <option :value="null">Please select a value</option>
    <option :value"1">One</option>
  </select>
  <button>submit</button>
</form>

(link to the complete jsfiddle)

This will now render as <option>Please select a value</option> , when in Vue 2, it was <option value>Please select a value</option>.

This does not matter when accessing the value in Vue where it will still be null, but when you submit the form, the native value will now be Please select a value instead of empty string. For example, the above code would redirect you to /?mySelect=Please+select+a+value. In Vue 2, it was /?. Same thing when accessing the values as event.target FormData.

This is a pretty daunting change and should be much more clearly stated imo.

The migration path here is probably to replace all option null bindings to '' bindings. Which can be quite annoying really, as it now adds a new extra transformation step for your models that you always need to keep in the back of your mind.


It is not very common to integrate Vue in native html forms anyway, unfortunately. While we're at it, I think that the guide should point to the power of html validation, with constraints via attributes. Sure, JS validation has its place, as well as validation libraries, has its place, since html is limited to string values. But arguably in most cases, html is enough, and often more reliable. And especially given Vue's low barrier entry and its tendency to draw novice programmers, we should explain this in more detail. Maybe in the cookbook? There is no Vue 3 cookbook entry about forms yet anyway (?)

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