我在symfony2中创建了表单,最后呈现按钮以提交表单。当我添加ng-app="myApp"
时,一切正常,但我无法提交此页面上的表单。为什么这样以及如何解除阻止?
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')
))
查看:
<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);
});
});
答案 0 :(得分:2)
出于这个原因,Angular会阻止默认操作(表单提交 除非元素具有action属性,否则到服务器) 指定的
因此您可以向表单添加操作属性。在我的示例中,我使用的是grenerateUrl函数,但是您应该生成当前路径的url(生成表单的控制器路径)
$data = array();
$form = $this->createFormBuilder($data,
array("action" => $this->generateUrl("route_to_curent_path"))))
->add('field', 'text')
->add('submitButton', 'submit')
->getForm();
答案 1 :(得分:0)
我们需要更多信息,您是否让浏览器验证表格?删除:
{{ form(form, {
'attr': {
novalidate,
},
})
}}
可能隐藏错误弹出窗口(发生在各种复杂的表单字段中)
当你说&#34;我无法提交&#34;时,提交按钮是否无效?总结之后会发生错误吗?