Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit form with dynamically changing action attribute

I'm trying to send form with dynamically changing action url, but right after changing attribute the form doesn't submits.

Here is simple example: http://jsfiddle.net/THZHL/1/

<div ng-app="app">
    <form name="b" action="{{url}}" methood="post" ng-controller="formCtrl">
        <button type="button" ng-click="set()">1. set url</button>
        <button type="submit">2. Send</button>
        {{url}}
    </form>
</div>
<script>
    app = angular.module("app", []);

    app.controller("formCtrl", function($scope){
        $scope.set = function(){
            $scope.url = "/abc";
        }
    });
</script>

I don't understand why it happens in that way.

like image 754
Pavel Frankov Avatar asked Jun 23 '26 19:06

Pavel Frankov


1 Answers

I found the solution! $scope.url should be set with any non-empty value. Like there:

http://jsfiddle.net/THZHL/2/

app.controller("formCtrl", function($scope){
    $scope.url = "/def";

    $scope.set = function(){
        $scope.url = "/abc";

    }
});
like image 162
Pavel Frankov Avatar answered Jun 26 '26 09:06

Pavel Frankov