Varun verma
Varun verma

Reputation: 189

warning "Form submission canceled because the form is not connected" in angular

html code:

 <form action="{{url}}"> 
            <input type="submit" class="btn btn-info" ng-
click="goToProdPage()" value="Resume">
           </form>

Angular Code:

    $scope.goToProdPage = function(){
    if(id){
        $scope.url = "#/"+id+"/cpq";
    console.log("done   "+id);
    $state.go("cpq");
    } 
}

Please ignore the id because i put only half code. I already used $(document.body).append(form); and it solved the issue but after adding it now its show bellow error on console

angular.js:14362 ReferenceError: form is not defined at b.$scope.findUser.$scope.goToProdPage (login.js:44) at fn (eval at compile (angular.js:15197), :4:156) at e (angular.js:26808) at b.$eval (angular.js:18017) at b.$apply (angular.js:18117) at HTMLInputElement. (angular.js:26813) at dg (angular.js:3617) at HTMLInputElement.d (angular.js:3605)

Upvotes: 2

Views: 1598

Answers (2)

user1141796
user1141796

Reputation: 324

Not 100% sure what you are trying to do here. But my opinion is that you should use a more an Angular-way of handling forms...

<form ng-submit="mySubmit()">
    <input type="submit" value="Send form">
</form>

Now you can write a function in your controller handling the form's submit.

this.mySubmit = mySubmit;

function mySubmit() {
    // Check here if the url exists
    // ...or what to do when submitting the form...
    // this.goToProdPage();
}

A more detailed example or extra information could help me better understand the issue :-)

Upvotes: 2

Anil Shrestha
Anil Shrestha

Reputation: 1200

first remove type submit from button and put id in form

<form id="myform" action="{{url}}"> 
   <input type="button" class="btn btn-info" ng-
click="goToProdPage()" value="Resume">
</form>

and in function goToProdPage() after all the processing is completed trigger the form submit with jquery

$scope.goToProdPage = function(){
    if(id){
       $scope.url = "#/"+id+"/cpq";
       console.log("done   "+id);
       $state.go("cpq");
       $('#myform').submit();
    }
} 

Upvotes: 1

Related Questions