Ng-submit fires many times on iphone

Hi,

I’m using ionic (beta.8) to create a phonegap app for iphone. I have this form which is opened in a modal. When the user submts the form, the modal is closed and the data is stored in local storage. However, when I tap or scroll the view from which the modal is opened, the ng-submit is triggered again with no data. Everthing works fine in the browser (chrome).

Here’s my modal with the form:

It’s the addEventForm function that triggers, and it looks like this (items is a service):

$scope.addEventForm = function() {

   var eventDesc = this.desc;

   var time = this.time;


   var eventTime = time;

   var eventName = this.myEvent;


   var eventNameSel = this.myEventIn;



       var eventUrl = this.url;


       items.addEvent(eventTime, eventName, eventNameSel, eventUrl, eventDesc).then(function(d) {
           $scope.results = d;
           console.log($scope.results);

           for (var i = 0, len = $scope.results.length; i < len; i++) {

               alert($scope.results[i].eventDesc);



           }


           $scope.closeModalNew();

       });

   }

All help much appreciated! And let me know if you need more code examples!

Hey there! So just to make sure I don’t miss anything, would you mind throwing this in a quick codepen?

Sure, haven’t done that before, but I’ll gite it a try. Will let you know when it’s done.

Ok, sorry for taking a little time to respond, but the problem seems to be more fundamental than this particular app. If I create a blank app from command line with:

ionic start myApp blank

And then add ios:
ionic platform add ios

And then I simply add a form tto index.html and a controller which simply alerts the input, the form works ok in the browser, but in the simulator there’s the same problem: When I submit there’s an alert, as it should be, and then when i press anywhere on the screen, theres a second submit triggered. Really strange, and obviously I have missed something here. Here’s a link to my codepen, which, as i wrote above, is just the blank starter app with a form. http://codepen.io/pauster/pen/KCckb

Would really appreciate your help with this. Thank’s!

Ok, so adding a if ( has value) condition prevents the alert (or submit if that’s what your doing), but the behaviour still seems a little strange to me. The function shouldn’t trigger at all when tapping the second time on the screen after submit, should it?

Hey, yeah I’m seeing this as well. Seems like it’s an angular issue, so an if would be the best way to prevent the empty submit.

.controller('TodoCtrl', function ($scope) {
    $scope.task = {}; //stop initial error
    $scope.createTask = function (task) {
        if (!$scope.task.title) return; //stop blank submit
       alert(task.title);
        task.title = "";
    };
});

Ok, thank’s for taking the time to answer. Maybe something to look at in later releases of ionic or maybe mention it in the documentation. Forms is such a vital part of almost any app, and this behavior seems a bit buggy. Just a thought. Overall I think ionoic looks extremely nice.

I agree, forms are a big part of apps. Most cases I’ve seen people building out big validation logic to make sure things aren’t empty. But for a simple use case, angular should be able to handle it…well thats what versions are for.