gsanta gsanta - 4 months ago 79
AngularJS Question

How to do validation in $ionicPopup?

I'm trying to use $ionicPopup to handle login/registration on my app.
I'm opening it from a service, so I created a new scope and attached it to the ionicPopup.
It looks smth like this:

template: '''
<form name="loginForm" novalidate>
scope: $scope,
buttons: [
text: 'Cancel',
text: '<b>Save</b>',
type: 'button-positive',
onTap: ( e ) ->

form = $scope.loginForm #why is it undefined?

So I named the form as loginForm, and I want to access it inside the onTap function to handle validation. But the loginForm does not exists on the $scope, like it would in a normal form validation inside a controller.
So do you have any idea how I should handle the validation here?



I figured out an ugly, but working solution that I'm currently using. If you give ionicpopup a templateUrl, instead of hard coded template string, you can use a regular controller inside the template that does the validation.

Right now I deleted all the ionicpopup related buttons (I found them really awkward anyway), and give the necessary buttons inside the template.

And in this way I can control the ionicpopup's state from the controller (for example closing the popup)

Tomorrow I create a jsFiddle example, in case any one is interested.

But if you have any better solution, please share :D