phiamo / MopaBootstrapBundle

Easy integration of twitters bootstrap into symfony2
http://bootstrap.mohrenweiserpartner.de
711 stars 348 forks source link

form_widget(form) .... problem ? #1196

Closed zigomario closed 7 years ago

zigomario commented 7 years ago

I try to use TabformType. No error but fields are not in tab : capture

The whole form is render to one page Of course, nothing add html code for tab boostrap work ( div class"tab-content" / div class="tab-pane" )

I have all check, i don't see my mistake. It's working for someone ?

zigomario commented 7 years ago

My solution :

{% block content %}
   <div class="row-fluid">
      <div class="span4">
        {{ form_tabs(form) }}
   </div>

<div class="span8">
  <div class="tab-content">
    <div id="cv_cv" class="tab-pane active">
        {{ form_widget(form.cv) }}
    </div>
    <div id="cv_plop" class="tab-pane">
        {{ form_widget(form.plop) }}
    </div>
  </div>
</div>

{% endblock content %}

But i think it's not the most easy solution

isometriks commented 7 years ago

Can you post your PHP form code?

zigomario commented 7 years ago

Thanks to regard;

## my FormType :

<?php

         namespace OC\PlatformBundle\Form;

    use Mopa\Bundle\BootstrapBundle\Form\Type\TabType;
     use Symfony\Component\Form\AbstractType;
     use Symfony\Component\Form\Extension\Core\Type\CollectionType;
     use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
      use Symfony\Component\Form\Extension\Core\Type\TextType;
      use Symfony\Component\Form\FormBuilderInterface;
     use Symfony\Component\OptionsResolver\OptionsResolver;

    class CvType extends AbstractType
    {

         public function buildForm(FormBuilderInterface $builder, array $options)
        {

            $info = $builder->create("cv", TabType::class, array(
                'label'=>'Info',
                'icon'=>'pencil',
                'inherit_data'=>true
           ));
    $info->add('nom',     TextType::class)
        ->add('prenom',    TextType::class)
        ->add('mail' , EmailType::class)
        ->add('phone', TextType::class)
        ->add('titre', TextType::class)
        ->add('portefolio', TextType::class)   ;

    $skills = $builder->create("competences", TabType::class, array(
        'label'=> 'Compétences',
        'inherit_data'=>true

    ));
    $skills->add('cvSkills', CollectionType::class, array(

        'entry_type'=> CvSkillType::class,
        'allow_add'=> true,
        'allow_delete'=>true,
        'by_reference'=>false,
    ))    ;

    $builder
        ->add($info)
        ->add($skills)
        ->add('save', SubmitType::class);

}

/**
 * @param OptionsResolver $resolver
 */
public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(

        'data_class' => 'OC\PlatformBundle\Entity\Cv'
    ));
}

}

My View :

` {% extends "MopaBootstrapBundle::layout.html.twig" %} {% from 'MopaBootstrapBundle::flash.html.twig' import session_flash %}

 {% block headline %}Form Tabs{% endblock headline %}

 {% block content %}
  <div class="">
   {{ form_start(form, {'attr': {'class': 'form-horizontal'}}) }}
      <div class="row-fluid">
         <div class="span4">
             {{ form_tabs(form) }}
         </div>

         <div class="span8">
             {{ form_widget(form) }}
          </div>
     </div>
   {{ form_end(form) }}
 </div>

 {% endblock content %}
`

And by the way,

When i try save form, error : Warning: spl_object_hash() expects parameter 1 to be object, array given

I don't use MopaBundle for my FormcollectionType Like it works without MopaBundle Tab i think that it's cause "->add($skills") don't return object "CvSkills". But what is my solution ?

Thanks

isometriks commented 7 years ago

Hmm, that all looks right. I will have to test a new symfony install and see if there is a bug. What version are you using?

zigomario commented 7 years ago

Ok. Symfo 3.

my requires :

 `    "require": {
    "php": ">=5.5.9",
    "symfony/symfony": "~3.0",
    "doctrine/orm": "^2.5",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/doctrine-cache-bundle": "^1.2",
    "symfony/swiftmailer-bundle": "^2.3",
    "symfony/monolog-bundle": "^2.8",
    "sensio/distribution-bundle": "^5.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "incenteev/composer-parameter-handler": "~2.0",
    "doctrine/doctrine-fixtures-bundle": "~2.2",
    "stof/doctrine-extensions-bundle": "^1.2.2",
    "friendsofsymfony/user-bundle": "dev-master",
     "mopa/bootstrap-bundle": "~3.1",
    "twbs/bootstrap": "~3.3.0",
    "knplabs/knp-paginator-bundle": "dev-master",
    "knplabs/knp-menu-bundle": "dev-master"

}`
isometriks commented 7 years ago

Hmm, I just wrote some tests to check markup for 3.0 and it seems to be rendering okay. Can you paste your mopa_bootstrap config? I haven't had a chance to create a test project yet

zigomario commented 7 years ago

to be honest, i m not sure to have understand config :

capture1 capture3

zigomario commented 7 years ago

it's two image. In real, i have no 2 times : class: col-sm-3 col-sm-offset-3 and widget_add_btn is correctly indent

zigomario commented 7 years ago

wowwwwwwwwwwww....bug find ! My bad sorry cause bootsrap template on twig :+1:

twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    form_themes:
        - 'bootstrap_3_layout.html.twig'

now next problem ^^ , after save form = Warning: spl_object_hash() expects parameter 1 to be object, (array given ) ... it's cause Formcollection used in tab. i hope to find.

Thanks for help

zigomario commented 7 years ago

Warning: spl_object_hash() expects parameter 1 => again and again my bad

Juste need to add option data_class=>'.../../entity' and 'inherit_data'=>true

I close