8000 Fully controlled form elements by CyberAP · Pull Request #188 · vuejs/rfcs · GitHub
[go: up one dir, main page]

Skip to content

Fully controlled form elements #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Composition API section
  • Loading branch information
CyberAP authored Jul 16, 2020
commit 2ead19dba51a7fe605bb3ddc5931cee21163dee0
34 changes: 32 additions & 2 deletions active-rfcs/0000-fully-controlled-form-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,37 @@ A Controlled version would not allow user input that doesn't correspond to final

## Current state

Vue implements uncontrolled approach for form elements bindings (i.e. elements that can accept user input).
Vue implements uncontrolled approach for form elements bindings (i.e. elements that can accept user input) in options API.

### Inconsistency with Composition API

Current `v-model` behaviour is inconsistent between options API or Composition API. The following code will produce a fully controlled `v-model` in Composition API:

```html
<template>
<input v-model="model">
</template>

<script>
import { ref } from 'vue'

export default {
setup() {
const message = ref(null)

return {
get model() { return message.value },
set model(value) {
if (value.length > 2) return
message.value = value
}
}
}
}
</script>
```

This RFC intends to align current options API behaviour with Composition API.

### Comparison with other frameworks

Expand Down Expand Up @@ -227,4 +257,4 @@ It's yet unclear how nested models should work that consist of both controlled a
Docs would have to be updated to reflect these changes.
Examples showcasing differences between controlled and uncontrolled elements would be a welcome addition as well.

It's possible to provide `v-model.uncontrolled` modifier for those affected by this change to retain old behaviour.
It's possible to provide `v-model.uncontrolled` modifier for those affected by this change to retain old behaviour.
0