Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have form created in symfony2, which at the end renders button to submit form. When I add ng-app="myApp" everything works fine, but I can't submit form which is on this page. Why is that and how to unblock this?

FORM:

->add('company','choice',array(
                'mapped' => false,
                'attr'=>array('ui-select2'=>'myArray', 'ng-model'=>'form.company','ng-options'=>'option.value as entity.name_company for entity in entities','ng-change' => 'changeItem()')
            ))

            ->add('project',null,array(
                'attr'=>array('ui-select2'=>'myArray2', 'ng-model'=>'form.task','ng-options'=>'option.value as entity.description_task for entity in tasks')
            ))

VIEW:

<html ng-app="flowApp">
<head>
    <link rel="stylesheet" href="{{ asset('external-libs/select2/select2.css')}}">
    <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
    <script src="{{ asset('external-libs/select2/select2.js')}}"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.5/angular.min.js"></script>
    <script src="{{ asset('external-libs/select2.js')}}"></script>
    <script src="{{ asset('external-libs/app.js') }}"></script>
        <style>
                .select2-choice { width: 220px; }
        </style>
</head>
<body>
    <div class="container" ng-controller="MainCtrl">
    {{ form(form) }}
    </div>
</body>
</html>

SCRIPT:

var app = angular.module('flowApp', ['ui.select2']).config(function($interpolateProvider){
        $interpolateProvider.startSymbol('{[{').endSymbol('}]}');
    }
);

app.controller('MainCtrl', function ($scope, $element,$http) {


    $http({method: 'GET', url: 'companies.json'}).
        success(function(data, status, headers, config) {

         $scope.entities = data.entities;
         $scope.form = {company: $scope.entities[0].value };
         console.debug(data.entities);
    });
});
share|improve this question
    
Can you add some code please? Are you using angular for anything here? –  GonchuB Apr 8 '14 at 13:06
    
yep, I'm using for the filling select with select2 script. I've added code. –  mmmm Apr 8 '14 at 13:13
    
Okay. First of all. $scope.forms is a variable, and you are invoking it as a function (why are you doing {{ form(form) }}?). Otherwise, are you seeing network traffic for your GET request? –  GonchuB Apr 8 '14 at 13:18
    
{{ form(form) }} is symfony function to render form..... –  mmmm Apr 8 '14 at 13:19
    
isn't it {[{ form(form) }]} ? –  GonchuB Apr 8 '14 at 15:25

2 Answers 2

Well documentation says:

For this reason, Angular prevents the default action (form submission to the server) unless the element has an action attribute specified

so you can add action attribute to your form. In my example i am using grenerateUrl function, but you should generate url of your current route(route of controller where the form is generated)

$data = array();
            $form = $this->createFormBuilder($data,
                array("action" => $this->generateUrl("route_to_curent_path"))))
                ->add('field', 'text')
                ->add('submitButton', 'submit')
                ->getForm();

EDIT: just now found out that this is a duplicate question here and here and here and here(this link being the most upvoted answer)

share|improve this answer

We need more informations, did you let browser validate form ? To remove :

{{ form(form, { 
    'attr': {
        novalidate,
    },
    }) 
}}

Maybe errors popup are hidden (happen with various complexe form fields)

When you said "i can't submit", is the submit button unable ? Errors happen after sumbission ?

share|improve this answer
    
nope, code is as simple as You see. When I remove "ng-app" than everything works just fine. submit button is enabled, just doesn't submit the form. –  mmmm Apr 9 '14 at 9:54
    
Had you try to remove auto-validation so ? It's the default behaviour on mostly recent browsers. –  Healkiss Apr 9 '14 at 9:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.