0

I'm trying to submit a form with AngularJS without use $http. I'm checking the form via Javascript, but not sure how to submit after the check is complete. Sample code looks like this:

AngularJS

 app.directive('checkLoggedinSubmit', ['account_id', 'session', 'LoginModal',
    function(account_id, session, LoginModal) {
        return {
            restrict : 'A',
            link : function(scope, element, attrs) {

                element.bind('submit', function(e) {
                    e.preventDefault();             

                    //If not logged in, show logged in, otherwise subit
                    if (!account_id && !session.read('account_id')) {
                        LoginModal.show();
                    } else {
                        scope.$eval(attrs.checkLoggedinSubmit);
                        scope.$apply();
                        //Tried To use JQuery
                        //$(e.currentTarget).submit();
                    }

                });

            }
        };

}]);

HTML Form

<form role="form" enctype="multipart/form-data" method="post" action="/file/submit" class="well" style="padding: 0px 20px 20px;" check-loggedin-submit >
    <div class="form-group">
        <input type="file" name="my_file" />
    </div>

    <div class="form-group">
        <input type="submit" class="btn btn-success"  />
    </div>

</form>

I tried to have JQuery submit the form, but threw errors. Anyone now how to solve this?

1
  • I think the simplest way is move the e.preventDefault(); call to inside your if statement, so it will be called only when needed. Commented Feb 6, 2015 at 5:09

2 Answers 2

2

better way to submit form in angular is using "ng-sbmit"

you can use something like ng-submit="functionHandlingSubmitTask()"

you can look into given link to

http://learnwebtutorials.com/angularjs-tutorial-submitting-form-ng-submit

Sign up to request clarification or add additional context in comments.

Comments

0

try it:

<input type="submit" data-ng-click="save(input) class="btn btn-success"  />

save is the JQuery method name and input is params.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.