我正在尝试提交一个应该停用多个文档的表单。点击“提交”按钮时没有任何反应。 这是我的枝条文件:
{% block content %}
{{ form_start(form) }}
{{ form(form.documentlist) }}
{{ form_end(form) }}
<p>
<div class="row">
<button type="submit">Submit</button>
</div>
{% endblock content %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('js/bootstrap-multiselect.js') }}"></script>
<script>
makeMultiselectDropdown('#{{ form.vars.name }}_documentlist', 'Select Document');
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#{{ form.vars.name }}_documentlist').change(function() {
var docId = $('#{{ form.vars.name }}_documentlist').val();
$.ajax({
type: "POST",
data: {'id': docId},
});
});
});
</script>
{% endblock %}
和我的控制器功能:
/**
* @Route("/document/bulkdeactivate", name="documentBundle_document_bulkDeactivate")
* @Template()
*/
public function bulkDeactivateAction(Request $request) {
$em = $this->getDoctrine()->getManager();
$selected_documents = $request->request->all();
$form = $this->createForm(DocumentDeactivationType::class);
$form->handleRequest($request);
if ($form->isValid() && $form->isSubmitted()) {
foreach($selected_documents as $document) {
$documentR = json_decode(json_encode($document), true);
dump($documentR);
for($i=0; $i<count($documentR); $i++){
$doc = $em->getRepository('DocumentBundle:Document')->findOneById($documentR[$i]);
dump($doc);
$document->setActive(false);
$em->persist($document);
$em->flush();
}
}
$this->addFlash(
'success',
'The document has been deactivated!'
);
return $this->redirectToRoute('documentBundle_document_list');
}
return $this->render('DocumentBundle:Panels:ActivationPanel.html.twig', array(
'form' => $form->createView(),
));
}
我在点击“提交”时查看了控制台,它说
Uncaught TypeError: Cannot set property 'href' of null
at window.onload (bulkdeactivate:257)
这是呈现树枝模板的线。我不知道这是否与我的问题有任何关系,只是想让我知道尽可能多的知识!
任何帮助将不胜感激!