Используйте ng-сообщение с ng-required

0

У меня есть форма, которая проверяет радиовход. Требуется радиовход (пользователю необходимо выбрать одно из полей радио, прежде чем нажимать кнопку отправки). Я использую для этого ng-требуемый во входном радио.

Радиовход выглядит примерно так:

<input type="radio" name="myRadio" value="1" ng-model="theModel" ng-required="!theModel">
<input type="radio" name="myRadio" value="2" ng-model="theModel" ng-required="!theModel">
<input type="radio" name="myRadio" value="3" ng-model="theModel" ng-required="!theModel">

Я хочу показать сообщение в моей форме после отправки пользователем. Я использую для этого директиву ng-message. Я использую его так:

<div class="msg-error-input" ng-if="!theModel" ng-messages="myForm.myRadio" role="alert">
    <div class="icon my-icon" ng-message="required">
        It has to show an error here. But this doesn't seem to work ! It seems that there no link between the ng-message='required' and the ng-required..
    </div>
</div>
  • 1
    умеешь ли ты возиться ... выглядит все нормально ...
Теги:
forms

1 ответ

1

Я решил, что:

<form name="myForm" id="myForm">
<input type="radio" name="myRadio" value="1" ng-model="theModel" ng-required="!theModel">
<input type="radio" name="myRadio" value="2" ng-model="theModel" ng-required="!theModel">
<input type="radio" name="myRadio" value="3" ng-model="theModel" ng-required="!theModel">
<div class="msg-error-input" ng-if="!theModel && submitted" ng-messages="myForm.myRadio" role="alert">
    <div class="icon my-icon" ng-message="required">
        It has to show an error here. But this doesn't seem to work ! It seems that there no link between the ng-message='required' and the ng-required..
    </div>
</div>
<button type="submit" data-ng-click="submitted"/>
</form>

(Я видел, что представленная ng не была добавлена в мою форму, поэтому я добавил переменную, представленную кликом)

Ещё вопросы

Сообщество Overcoder
Наверх
Меню