Angular 在第一个表单验证/承诺后提交第二个表单

Angular to submit second form after first form validation/promise

本文关键字:表单 提交 第二个 承诺 验证 第一个 Angular      更新时间:2023-09-26

我正在提交一个带有 Angular 中 update() 函数的表单,然后进行身份验证,返回一个承诺,如果成功,则提交第二个表单。

问题是,第二个表单不会与document.getElementById(elementID).submit()一起提交。 方法。但是,它将使用 document.getElementById(elementID).click();但当然只能在非触摸设备上。

底线 - 为什么提交()不起作用?

这是一个带有简化和简化版本的jsFiddle:http://jsfiddle.net/jimcamut/xos805gk/

这是我处理完整版表单提交的函数。

$scope.update = function(user) {
        if ($scope.earlyUser.$valid) {
            $scope.master = angular.copy(user);
            console.log("Form submitted on front end");

            // This integrates ParseJS and submits the data to a database - all good here, except after the promise
            var parseUser = new Parse.Object("LaunchUser");
            parseUser.setACL(new Parse.ACL());
            parseUser.save({
                name: $scope.master.name,
                email: $scope.master.email,
                zipcode: $scope.master.zipcode
            },{
                error: function(model, error) {
                    console.log("error is...");
                    console.log(error);
                }
            // Returns a promise
            }).then(function(object) {

                // Problem area here when attempting to submit second form...
                document.getElementById('mc-embedded-subscribe').submit();

                $scope.reset();
            });
        } else {
            alert("Please correct the red form fields.");
        }
    };

id='mc-embedded-subscribe' 的元素是一个输入,但你需要 "submit()" 一个表单。这条线

document.getElementById('mc-embedded-subscribe').submit();

应更改为

document.getElementById('mc-embedded-subscribe-form').submit();

在这里,您对此更改有了新的小提琴,并且它有效!http://jsfiddle.net/kx8dn8wc/