-
Notifications
You must be signed in to change notification settings - Fork 431
v-bind:class="$validation1.mywords.valid ? 'has-success' : 'has-error'" do not work! #120
Comments
Thank you for your feedback! 😸 I checked your code. the above code, I think that there is no problem. Can you provide the code to us ? |
<!-- demo root element -->
<div id="demo3">
<validator name="validation1">
<form id="search" novalidate>
<!-- BUG? 在 v-bind:class 中无法使用下面的表达式 -->
<div class="form-group "
v-bind:class="$validation1.mywords.valid ? 'has-success' : 'has-error'"
>
<label class="control-label">关键字</label> <input name="query"
class="form-control"
v-validate:mywords="{ maxlength: 2, required:true }"
v-model="searchQuery">
</div>
</form>
<div class="alert alert-danger" v-show="!$validation1.mywords.valid">
<span v-show="$validation1.mywords.required">关键字必须填写!</span>
<span v-show="$validation1.mywords.maxlength">关键字最大长度为 2 个字符!</span>
</div>
<pre> {{ $validation1 | json }} </pre>
</validator>
<table-ctl
test-prop="asdf"
:data="gridData"
:columns="gridColumns"
:filter-key="searchQuery">
</table-ctl>
</div> Uncaught TypeError: Cannot read property 'valid' of undefined(anonymous function) @ VM1470:3Watcher.get @ vue.js:3112Watcher @ vue.js:3080Directive._bind @ vue.js:7716linkAndCapture @ vue.js:6404compositeLinkFn @ vue.js:6382Fragment @ vue.js:4409FragmentFactory.create @ vue.js:4611insert @ vue.js:4653insert @ vue-validator.js:764render @ vue-validator.js:759(anonymous function) @ vue-validator.js:748(anonymous function) @ vue.js:216_dir.vm.(anonymous function) @ vue-validator.js:598bind @ vue-validator.js:753Directive._bind @ vue.js:7696linkAndCapture @ vue.js:6404compositeLinkFn @ vue.js:6382Vue._compile @ vue.js:7980Vue.$mount @ vue.js:8945Vue._init @ vue.js:2408Override.Vue._init @ vue-validator.js:317Vue @ vue.js:9004(anonymous function) @ test_ctl.html:249h.execCb @ require.js:30Z.check @ require.js:18(anonymous function) @ require.js:23(anonymous function) @ require.js:8(anonymous function) @ require.js:24v @ require.js:7Z.emit @ require.js:24Z.check @ require.js:19(anonymous function) @ require.js:23(anonymous function) @ require.js:8(anonymous function) @ require.js:24v @ require.js:7Z.emit @ require.js:24Z.check @ require.js:19(anonymous function) @ require.js:23(anonymous function) @ require.js:8(anonymous function) @ require.js:24v @ require.js:7Z.emit @ require.js:24Z.check @ require.js:19Z.enable @ require.js:23Z.init @ require.js:17E @ require.js:14h.completeLoad @ require.js:28h.onScriptLoad @ require.js:30 |
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="vue.js"></script>
<script type="text/javascript" src="vue-validator.js"></script>
</head>
<body>
<div id="demo3">
<validator name="validation1">
<form id="search" novalidate>
<!-- BUG? v-bind:class can not access $validation1.mywords ? -->
<div class="form-group " v-bind:xxx="$validation1.mywords.valid ? 'has-success' : 'has-error'"
v-bind:class="{'asdf':$validation1.mywords.valid}">
<label class="control-label">Please Enter:</label>
<input class="form-control" v-validate:mywords="{ maxlength: 2, required:true }" />
</div>
</form>
<div class="alert alert-danger" v-show="!$validation1.mywords.valid">
<span v-show="$validation1.mywords.required">must not empty!</span>
<span v-show="$validation1.mywords.maxlength">maxlength = 2!</span>
</div>
<pre> {{ $validation1 | json }} </pre>
</validator>
</div>
<script language="javascript">
Vue.config.debug = true;
var vm = new Vue({
el: '#demo3',
data: {
}
})
</script>
</body>
</html> Download the Vue Devtools for a better development experience: |
Thank you for your reporting!! I guess that this issue related #35 #103 #111 we can avoid this issue by setting the |
Thanks a lot for your response! |
But if you set |
I'm still having this issue, specifically when used in the following:
If not binding on the same element as the validate, I don't see this happen. |
I confirm, the issue still persists
triggers Is there any way this can be fixed without having to set |
This warning error is difficult to avoid perfectly in vue-validator. We can avoid to use computed property. computed: {
userValid: function () {
return this.$validation.user && this.$validation.user.valid ? '' : 'error'
}
} |
The text was updated successfully, but these errors were encountered: