ajax - symfony2:How to selection one field to view using formType table -


i want show 1 field using ajax edit field have in formtype fields of table formtype

    public function buildform(formbuilderinterface $builder, array $options) {         $options = array('multiple' => 'multiple');         $builder                 ->add('name', 'text', array(                     'label' => 'company name',                 ))                 ->add('abbreviation', 'text', array(                     'required' => false,                     'label' => 'abbreviation',                 ))                 ->add('description', 'textarea', array(                     'required' => false,                 ))                 ->add('city', 'text', array(                     'required' => false,                 ))                 ->add('address', 'text', array(                     'required' => false,                 ))                 ->add('facebook', 'url', array(                     'required' => false,                 ))                 ->add('linkedin', 'url', array(                     'required' => false,                 ))                 ->add('twitter', 'text', array(                     'required' => false,                 ))                 ->add('youtube', 'url', array(                     'required' => false,                 ))                 ->add('googleplus', 'text', array(                     'required' => false,                 ))                 ->add('skype', 'text', array(                     'required' => false,                 ))                 ->add('chairman', 'text', array(                     'required' => false,                 ))                 ->add('managingdirector', 'text', array(                     'required' => false,                 ))                 ->add('contactperson', 'text', array(                     'required' => false,                 ))                 ->add('contactpersontitle', 'text', array(                     'required' => false,                 ))                 ->add('contactpersonphone', 'text', array(                     'required' => false,                 ))                 ->add('isactivated', 'checkbox', array(                     'required' => false,                 ))                 ->add('countryid', 'entity', array(                     'label' => 'country',                     'class' => 'custom\cmsbundle\entity\country',                     'query_builder' => function (entityrepository $er) {                         return $er->createquerybuilder('u')                                 ->orderby('u.name', 'asc');                     }                 ))                 ->add('owner')                 ->add('class')                 ->add('level', 'choice', array(                     'choices' => array(                         '1' => '1',                         '2' => '2',                         '3' => '3',                         '4' => '4',                         '5' => '5',                         '6' => '6',                         '7' => '7',                         '8' => '8',                         '9' => '9',                         '10' => '10',                     )                 ))                 ->add('phonechairman', 'text', array(                     'required' => false,                 ))                 ->add('mobilechairman', 'text', array(                     'required' => false,                 ))                 ->add('faxchairman', 'text', array(                     'required' => false,                 ))                 ->add('emailchairman', 'text', array(                     'required' => false,                 ))                 ->add('phonemanagingdirector', 'text', array(                     'required' => false,                 ))                 ->add('mobilemanagingdirector', 'text', array(                     'required' => false,                 ))                 ->add('faxmanagingdirector', 'text', array(                     'required' => false,                 ))                 ->add('emailmanagingdirector', 'text', array(                     'required' => false,                 ));     } 

how can return form edit 1 field using ajax if answer hide field, how can set field not hide

i don't know field want edit ajax, suppose it's "name". , suppose entity entity1 (entity1.php user.php entity).

then have create specific editform use case. example : editentity1form1 (choose best name)

then editentity1form1 have :

public function buildform(formbuilderinterface $builder, array $options) {         $options = array('multiple' => 'multiple');         $builder             ->add('name', 'text', array(                 'label' => 'company name',             )); }  /**  * @param optionsresolverinterface $resolver  * specifies entity corresponding editing form  */ public function setdefaultoptions(optionsresolverinterface $resolver) {     $resolver->setdefaults(array(         'data_class' => 'directory_to_your_entity\entity1'     )); } 

now in controller, you'll have speficy in ajax edit action use editentity1form1 :

/** * creates form edit entity1 entity. * * @param entity1 $entity entity * your_form_route_name_here route name of action want associate edit form (if submit edit form, make post route. can action route in twig view , post in ajax way want. * * @return \symfony\component\form\form form */ private function createeditform(entity1 $entity) {     $form = $this->createform(new editentity1form1(), $entity, array(         'action' => $this->generateurl('your_form_route_name_here', array('id' => $entity->getid())),         'method' => 'post',     ));      return $form; } 

and controller can have : http://intelligentbee.com/blog/2015/01/19/symfony-2-forms-and-ajax/

in ajax post action have these lines :

 $editform = $this->createeditform($entity);  $form->handlerequest($request); 

these lines specify use editentity1form1. $entity got :

$entity = $em->getrepository('yourbundle:entity1')->find($id); 

where $id passed post ajax action.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -