D
D
Demid Borodin2014-12-16 15:33:09
Angular
Demid Borodin, 2014-12-16 15:33:09

How to check if the Radio option is selected?

In the form, you need to check if radio is selected, with text, select, nuber, figured it out, but with radio, no way.
Actually the code.

<div>
    <label>Уровень сотрудника</label>
    <input type="radio" name="level" value="1" id="level-1" ng-model="workpeople.level"/> <label for="level-1" required="">1</label>
    <input type="radio" name="level" value="2" id="level-2" ng-model="workpeople.level"/> <label for="level-2" required="">2</label>
    <input type="radio" name="level" value="3" id="level-3" ng-model="workpeople.level"/> <label for="level-3" required="">3</label>
</div>
<div>
    <label>Семейное положение</label>
    <input type="radio" name="pokemon" value="1" id="married-1" ng-model="workpeople.isMarried"><label for="married-1">В браке</label>
    <input type="radio" name="pokemon" value="0" id="married-0" ng-model="workpeople.isMarried"><label for="married-0">Не в браке</label>
</div>
<div>
    <label>Наличие фотоаппарата</label>
    <input type="radio" name="photo" value="1" id="photo-1" ng-model="workpeople.isPhoto"/> <label for="photo-1">Есть</label>
    <input type="radio" name="photo" value="0" id="photo-0" ng-model="workpeople.isPhoto"/> <label for="photo-0">Нет</label>
</div>
<div>
    <label>Наличие интернета</label>
    <input type="radio" name="internet" value="1" id="internet-1" ng-model="workpeople.isInternet"/> <label for="internet-1">Есть</label>
    <input type="radio" name="internet" value="0" id="internet-0" ng-model="workpeople.isInternet"/> <label for="internet-0">Нет</label>
</div>

That is, if all Radios are unchecked, the form remains ng-invalid.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2014-12-16
@demidborodin

You can simply set the default value of the scope.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question