NVDA使用role =“alert”忽略角度* ngIf块

时间:2017-01-11 08:18:22

标签: angularjs typescript wai-aria nvda

我的目标是向用户提供有关输入错误的信息。通过这个例子,我能够做到没有角度。我还设法使用“innerHTML”属性重新创建了以下示例,但它也无法与NVDA一起使用,简而言之,它只是在发生错误时将一个节点附加到正文

<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>Contact form (WAI-ARIA)</title>
<script type="text/javascript">
  function removeOldAlert()
  {
    var oldAlert = document.getElementById("alert");
    if (oldAlert)
      document.getElementById("error").removeChild(oldAlert);
  }

  function addAlert(aMsg)
  {
    removeOldAlert();
    var newAlert = document.createElement("div");
    newAlert.setAttribute("role", "alert");
    newAlert.setAttribute("id", "alert");
    var msg = document.createTextNode(aMsg);
    newAlert.appendChild(msg);
    document.getElementById("error").appendChild(newAlert);
  }

  function checkEntryValidity(aID, aSearchTerm, aMsg)
  {
    var elem = document.getElementById(aID);
    var invalid = (elem.value.indexOf(aSearchTerm) < 0);
    if (invalid) {
      elem.setAttribute("aria-invalid", "true");
      addAlert(aMsg);
    } else {
      elem.setAttribute("aria-invalid", "false");
      removeOldAlert();
    }
  }
</script>
</head>
<body>
<form method="post" action="post.php">
<fieldset><legend>Please enter your contact details</legend>
<label for="name">Your name (required):</label>
<input name="name" id="name" aria-required="true" onblur="checkEntryValidity('name', ' ', 'Invalid name entered!');" aria-invalid="true" value=""><br>
<label for="email">E-Mail address (required):</label>
<input name="email" id="email" aria-required="true" onblur="checkEntryValidity('email', '@', 'Invalid e-mail address');" aria-invalid="true" value=""><br>
<label for="website">Website (optional):</label>
<input name="website" id="website" value="">
</fieldset>
<label for="message">Please enter your message (required):</label><br>
<textarea name="message" id="message" rows="5" cols="80" aria-required="true"></textarea><br>
<input name="submit" value="Send message" type="submit">
<input name="reset" value="Reset form" type="reset">
</form>
<div id="error"></div>

</body></html>

screenshot with working example (警告输入的名称无效!)

但是NVDA会忽略此类警报消息

<!-- widget with model binding here -->    
<div role="alert" class="validation" *ngIf="model.hasErrors()">
        <div *ngFor="let message of model.errors">{{message}}</div>
    </div>

screenshot with failure

我不知道为什么NVDA没有注册内容更改。

Angular2

我使用的是Windows 10,Firefox 50.1.0和NVDA 2016.4。

1 个答案:

答案 0 :(得分:3)

似乎添加咏叹调 - 像这样生活

   <div aria-live="assertive">
    <div role="alert" class="validation" *ngIf="model.hasErrors()">
        <div *ngFor="let message of model.errors">{{message}}</div>
    </div>
   </div>

允许读者注册更改。