Skip to content

Commit 99ebd51

Browse files
committed
add v-model read only filter warning
1 parent bdae247 commit 99ebd51

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/directives/model/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ module.exports = {
2626
*/
2727

2828
bind: function () {
29+
// friendly warning...
30+
var filters = this.filters
31+
if (filters && filters.read && !filters.write) {
32+
_.warn(
33+
'It seems you are using a read-only filter with ' +
34+
'v-model. You might want to use a two-way filter ' +
35+
'to ensure correct behavior.'
36+
)
37+
}
2938
var el = this.el
3039
var tag = el.tagName
3140
var handler

test/unit/specs/directives/model_spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,5 +473,18 @@ if (_.inBrowser) {
473473
expect(_.warn).toHaveBeenCalled()
474474
})
475475

476+
it('warn read-only filters', function () {
477+
var vm = new Vue({
478+
el: el,
479+
template: '<input v-model="abc | test">',
480+
filters: {
481+
test: function (v) {
482+
return v
483+
}
484+
}
485+
})
486+
expect(_.warn).toHaveBeenCalled()
487+
})
488+
476489
})
477490
}

0 commit comments

Comments
 (0)