1

Why this verifying dont work?I need that when the button is clicked, you need to check if the input is empty.

controller:

$scope.closeCart = function(){ if(!$scope.name){ $scope.modal.hide(); $scope.items.splice($scope.items); } else{ $ionicPopup.alert({ title: "Coloque um nome de identificação para retirada do produto!", okText: "Confirmar", okType: "button-dark" }); } }; 

html:

<label class="item item-input"> <span class="input-label">Name:</span> <input ng-model="name" type="text" placeholder="your name"> </label> <button class="button button-large button-full button-assertive" ng-click="closeCart()">Pagar</button> 
1
  • Maybe your input isn`t empty, because there are some spaces or something like that Commented May 2, 2016 at 21:59

3 Answers 3

2

Why you dont use form validation?

<form name="myForm"> <label class="item item-input"> <span class="input-label">Name:</span> <input name="name" ng-model="name" type="text" placeholder="your name" required> </label> <label ng-show="myForm.name.$invalid"> your error message</label> <button class="button button-large button-full button-assertive" ng-disabled="myForm.$invalid" ng-click="closeCart()">Pagar</button> </form> 
Sign up to request clarification or add additional context in comments.

3 Comments

thank you, but i like to know why the way i'm doing dont work :/
@FelipeCustodio Then you must post your whole code. Because nothing seems to be wrong... Best way is to make a plunkr or jsfiddle
if I need to do something like that again i will, but for now i think the form validation is a very good option.
0

I think you are calling the wrong function on the ng-click event:

wrong: ng-click="fecharPedido()" correct: ng-click="closeCart()" 

Best, Fabian

1 Comment

sorry I forgot to translate this part
0

You are defining var alertPopup but never calling it. You can try either removing var alertPopup = or adding alertPopup(); at the end of your else block.

As a side note, $ionicPopup uses promises, so you can follow your alertPopup with a .then block to perform additional processing after the popup closes.

You can find more details here.

4 Comments

Were you able to fix the issue, or are you still having trouble with it?
Still not getting into if
How are you testing this? Are you using ionic serve or are you testing on a device/emulator?
i'm using ionic lab to teste

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.