【问题标题】:Angular Directive to mark a field as dirty when tabbed throughAngular 指令在通过选项卡时将字段标记为脏
【发布时间】:2016-05-04 16:59:27
【问题描述】:

我一直在开发一个 Angular 应用程序,我需要能够通过字段进行选项卡

- 如果需要,请通过验证
- 如果不是,将它们标记为脏

通过这种方式在字段中切换将显示必填字段为错误,但在与它们交互之前,它们不会引发错误。

【问题讨论】:

    标签: javascript angularjs validation tabs directive


    【解决方案1】:
    return {
      restrict: 'A',
      require: "ngModel",
      link: function (scope, element, attrs, modelCtrl) {
        element.bind('blur', (change) => {
          if ((element.val() == '') && (attrs.required)){
            modelCtrl.$setValidity('tabValidate', false);
          }else{
            modelCtrl.$setValidity('tabValidate', true);
          }
            modelCtrl.$setDirty();
          });
        }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      • 2015-07-13
      • 1970-01-01
      相关资源
      最近更新 更多