why520crazy / angular-w5c-validator

a simple plugin for angular.js form validation
http://why520crazy.github.io/angular-w5c-validator
468 stars 162 forks source link

如何配置非全局的验证 #42

Closed hudoro closed 8 years ago

hudoro commented 8 years ago

如何配置局部的验证?好像例子都是配置全局验证的,能支持局部验证吗?就是我提交表单之后,在提交方法上去做验证

why520crazy commented 8 years ago

在提交表单之后做验证是什么意思?

hudoro commented 8 years ago

就比如下面代码这种验证,如何实现
vm.saveEntity = function ($event) { if(entity.costPrice>entity.marketPrice){ //原价不能大于市场价格 return false; } //do somethings for bz alert("Save Successfully!!!"); };

<form w5c-form-validate="validateOptions" novalidate name="validateForm" class="form-horizontal  w5c-form">  
        <div class="form-group">
            <label class="col-sm-2 control-label">原价</label> 
            <div class="col-sm-10"><input type="text" name="costPrice" ng-model="entity.costPrice" required></div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">市场价</label> 
            <div class="col-sm-10"><input name="marketPrice" ng-model="entity.marketPrice" required></div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="buttom" w5c-form-submit="vm.saveEntity()" class="btn btn-success"> 验证</button>
            </div>
        </div>
    </form>
why520crazy commented 8 years ago

目前这种级联的验证 只能自己写自定义表达式来完成,类似于 w5cRepeat,之后会考虑添加自定义验证的方法,这样就可以轻松满足你的需求