连接径向输入和文本输入

时间:2017-08-09 14:07:01

标签: angularjs forms angularjs-ng-model

我有带有径向按钮的表格,但最后一个是径向按钮和文本输入的组合。我想以某种方式连接两个输入。在单击旁边的径向按钮之前,用户不应该输入文本。此外,当用户开始写文本时,我想停止径向按钮检查指示消失。如果用户单击其他一些径向按钮,则文本字段应自行清空。

<label class="form-check-label">
  <input type="radio" name="religion" value="noSay" ng-model="$ctrl.diversityTest.religion">Prefer not to say
</label>

<label class="form-check-label">
  <input type="radio" name="religion" value="{{$ctrl.diversityTest.religion}}"> Any other religion or beliefe:
  <div>
     Please write in: <input ng-keyup="$ctrl.diversityTest.religion = $ctrl.diversityTest.temp" class="input-material" type="text" name="religion" ng-model="$ctrl.diversityTest.temp">
  </div>
</label>

1 个答案:

答案 0 :(得分:0)

您可以尝试这样: -

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.$ctrl = {};
  $scope.$ctrl.diversityTest = {};
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<body>

  <div ng-app="myApp" ng-controller="myCtrl">

    <label class="form-check-label">
  <input type="radio"  ng-click="$ctrl.diversityTest.temp='';$ctrl.diversityTest.otherReligionRadio='';" name="religion" value="noSay" ng-model="$ctrl.diversityTest.religion">Prefer not to say
</label>

    <label class="form-check-label">
  <input type="radio" name="religion" value="Other_religion" ng-model="$ctrl.diversityTest.otherReligionRadio" > Any other religion or beliefe:
  <div>
     Please write in: <input class="input-material" type="text" ng-disabled="!($ctrl.diversityTest.otherReligionRadio)" ng-keyup="$ctrl.diversityTest.religion = $ctrl.diversityTest.temp"  name="religion" ng-model="$ctrl.diversityTest.temp">
  </div>
</label>

    <br> Religion : {{$ctrl.diversityTest.religion}}
  </div>