How to make a required ion-radio, or make the button inactive while not choosing an option?

Asked

Viewed 36 times

0

How can I make an ion-radio as required, or disable the button if nothing is selected?

  <ion-radio ng-model="escolhido.categoria_comida_cod_categoria_com" ng-value="'{{item.categoria_comida_cod_categoria_com}}'" ng-required="true">{{item.categoria_comida_nome}}</ion-radio>

Follow with the button:

 <ion-list ng-repeat="item in categoriass | filter:q as results" ng-init="$last ? fireEvent() : null">

            <ion-radio ng-model="escolhido.categoria_comida_cod_categoria_com" ng-value="'{{item.categoria_comida_cod_categoria_com}}'" ng-required="true">{{item.categoria_comida_nome}}</ion-radio>
        </ion-list>


        <div class="spacer" style="width: 300px; height: 40px;"></div>

        <button class="button button-full button-assertive" ng-click="SelecionaCategoria(escolhido)">
            Continuar (Passo 1 de 2)
        </button>

1 answer

0


I used POG (Gambiarra-oriented programming)!

ng-required does not accept. Where this if finds nothing, but also does not let pass if there is nothing selected. Nor does Alert give... total POG.

$scope.SelecionaCategoria = function () {



            if (($scope.escolhido.categoria_comida_cod_categoria_com).length === null) {
                slert('É PRECISO UMA CATEGORIA');
            } else {

                $ionicLoading.show();

                var url = "?cod_categoria=" + $scope.escolhido.categoria_comida_cod_categoria_com + "&categoria=" + $scope.escolhido.categoria_comida_nome + ""
                console.log(url);


                var encodedurl = encodeURI(url);
                $ionicLoading.hide();
                window.localStorage.setItem("cod_categoria", $scope.escolhido.categoria_comida_cod_categoria_com);

                $state.go('nhaac.formDelicias');

            }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.