如果输入字段没有值而没有焦点,则使用angularjs执行操作

时间:2015-04-15 17:13:49

标签: javascript angularjs

我有一个已禁用的输入字段列表,其中一个已启用的输入字段位于顶部。 的 Plunker

快速浏览:

enter image description here

如果您专注于"命名此组" 输入字段,首先禁用输入字段将启用活动类。

我想要的是,如果"没有任何价值,请将此群组命名为#34; ,而不是重点关注它将会回到原来的状态。意味着第一个子输入将返回禁用状态,活动类将再次被删除。

任何帮助实现此行动都将受到高度赞赏。

我的代码:

$scope.focusGroup = function(i) {

    $scope.csTagGrp[i].csTags[0].active = true;

  };

  $scope.focusItem = function(i, parent_i) {
    $scope.csTagGrp[parent_i].csTags[i].old = true;
    if ($scope.csTagGrp[parent_i].csTags[i + 1]) {
      $scope.csTagGrp[parent_i].csTags[i + 1].active = true;
    } else if ($scope.csTagGrp[parent_i + 1]) {
      $scope.csTagGrp[parent_i + 1].csTags[0].active = true;
    }
  };

1 个答案:

答案 0 :(得分:1)

您可以在第二个字段上使用某些角度表达式来设置类和/或切换ngDisabled。

<input type="text"
       ng-model="fieldZero"/>
<input type="text"
       ng-model="fieldOne"
       ng-class="{active: fieldZero.length > 0}"
       ng-disabled="!(fieldZero.length > 0)"/>