【发布时间】:2016-04-26 12:53:22
【问题描述】:
我在使用 AngularJS 验证表单中的自定义指令时遇到问题。我创建的指令称为 switcher,它被放入一个表单 ChoixController 表单中。
代码是这样的:
<form id="choixContext" name="choixContext" ng-submit="choixController.save(choixContext)">
<label for="choixDevis">Choice of Devis </label>
<switcher name="choixDevis" id="choixDevis" grid="'grid-3-small-3-tiny-1'" values="choixContextContrat" model="codeChoix"/>
<div class="msg-error-input"
ng-if="!codeChoix"
ng-messages="choixContext['codeChoix'].$error"
role="alert">
<div class="icon icon-mobile-attention-carre" ng-message="required">
Erreur !
</div>
</div>
<button type="submit">Submit</button>
</form>
我该怎么做?我希望该指令是必需的。用户必须在提交前选择点击指令。
这是指令的 HTML 代码:
<div class="switcher {{grid}}" ng-cloak>
<label class="switch {{item.class}}"
data-ng-repeat="item in values">
<input name="{{name}}" type="radio" value="{{item.code}}" ng-model="$parent.model">
<span class="switch-data">
<span class="icon {{item.icon}}" data-ng-if="item.icon"></span>
<span class="switcher-libelle" data-ng-bind-html="item.libelle"></span>
</span>
</label>
<label class="switch switch-other" data-ng-if="otherRadio">
<input id="{{otherRadioId}}" name="{{name}}" type="radio" value="{{otherRadioValue}}" ng-model="$parent.model">
<span class="switch-data" data-ng-bind-html="otherRadioLibelle"></span>
</label>
</div>
【问题讨论】:
-
顺便说一句,在屏幕上显示您的客户名称可能不是一个好主意。
-
你是对的。我编辑了我的帖子。感谢您的帮助!
标签: javascript angularjs angular-directive