javascript - symfony2 advanced select in form -
is there way add client side either collection or drop down based on user selected in drop down in main form ?
i had same problem. use jquery part of collection (extra input fields). in controller have form builder creates , returns inputs html. can add condition , pass parameters (i use post , testing) , different collection.
/** * @route("/gcco/{id}", name="name", options={"expose"=true}) * @method({"get", "post"}) */ public function functionname($id){ $defaultdata = array('message' => 'type here'); $form = $this->createformbuilder($defaultdata, array('csrf_protection' => false)); $form->add('name', 'type', array( 'label' => 'label', 'label_attr' => array( 'title' => 'title', ), 'required' => false, )); } } $form = $form->getform(); $html = $this->renderview('yourbundle:default:form.html.twig', array('form' => $form->createview())); return new jsonresponse( array( 'html' => $html ) ); } and in form.html.twig file add input fields:
{{ form_widget(form) }} in jsonresponse collection.
maybe it's not best way works me every time.
other way pass json javascript , build inputs there.
Comments
Post a Comment