Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Custom form field type with 3 fields into - cannot add children to simple form
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Claus Jul Larsen  
View profile  
 More options Nov 3 2012, 4:05 am
From: Claus Jul Larsen <cl...@julsmed.dk>
Date: Sat, 3 Nov 2012 01:05:12 -0700 (PDT)
Local: Sat, Nov 3 2012 4:05 am
Subject: Custom form field type with 3 fields into - cannot add children to simple form

Hello!

In buildForm i'm calling the googlemap field type which is a custom field
(called by service container) type with 3 fields into:

$builder

->add('gmap_position','googlemap',array('dbrow'=>$builder->getData(),'mapse ttings'=>array('map_id'=>'map_canvas','width'=>'600px','height'=>'400px')))
            ->add('text','ckeditor')
            ->add('status','status')
        ;

The google map field type is here - i'm adding 3 fields in the form builder
- but get the error

You cannot add children to a simple form. Maybe you should set the option
"compound" to true?

<?php

namespace Mediauna\AdminBundle\Form\FieldTypes;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormTypeInterface;
use Ivory\GoogleMapBundle\Model\MapTypeId;
use Ivory\GoogleMapBundle\Model\Map;

class GoogleMapType extends AbstractType {

    private $map;
    private $event;
    private $doctrine;

    public function __construct(ContainerInterface $service) {
        $this->map = $service->get('ivory_google_map.map');
        $this->mapEvent = $service->get('ivory_google_map.event');
        $this->doctrine = $service->get('doctrine');
    }

    public function getDefaultOptions(array $options) {
        return array('mapsettings' => array(
                'map_id' => 'map_canvas',
                'width' => '600px',
                'height' => '400px',
            ),
            'dbrow' => array()
        );
    }

    public function buildForm(FormBuilderInterface $builder, array
$options) {
        $builder
*            ->add('gmap_position', new HiddenType())*
*            ->add('gmap_center', new HiddenType())*
*            ->add('gmap_zoomlevel', new HiddenType())*
        ;
    }

    public function buildView(FormView $view, FormInterface $form, array
$options) {
        parent::buildView($view, $form, $options);

        $mapSettings = $options['mapsettings'];

        /** @var $map Ivory\GoogleMapBundle\Model\Map */
        $map = $this->map;

        // Configure your map options
        $map->setPrefixJavascriptVariable('map_');
        $map->setHtmlContainerId('map_canvas');

        $map->setAsync(true);

        $map->setAutoZoom(false);

        $map->setCenter(20, 20, true);
        $map->setMapOption('zoom', 2);

        $map->setBound(-2.1, -3.9, 2.6, 1.4, true, true);

        $map->setMapOption('mapTypeId', MapTypeId::SATELLITE);

        $map->setMapOption('disableDefaultUI', true);
        $map->setMapOption('disableDoubleClickZoom', true);
        $map->setMapOptions(array(
            'disableDefaultUI' => false,
            'disableDoubleClickZoom' => true
        ));

        // Configure your event
        $event = $this->mapEvent;
        $event->setInstance($map->getJavascriptVariable());
        $event->setEventName('click');

        $handle = '
            function(e) {
                var marker = new google.maps.Marker({position:
e.latLng,map: '.$map->getJavascriptVariable().'});
                '.$map->getJavascriptVariable().'_clearOverlays();
                '.$map->getJavascriptVariable().'_markers.pop(0);
                '.$map->getJavascriptVariable().'_markers.push(marker);

$("#'.$map->getJavascriptVariable().'_position").val(e.latLng.lat()+","+e.l atLng.lng());
            }
        ';

        $event->setHandle($handle);

        // It can only be used with a DOM event
        // By default, the capture flag is false
        $event->setCapture(true);
        $map->getEventManager()->addDomEvent($event);

        $map->setLanguage('en');
        $view->vars['map'] = $map;

        $view->vars['map_js_variable'] = $map->getJavascriptVariable();
        $view->vars['width'] = $mapSettings['width'];
        $view->vars['height'] = $mapSettings['height'];
        $view->vars['map_id'] = $mapSettings['map_id'];

        $dbrow = $options['dbrow'];

        #$view->vars['map_center'] = $dbrow->getGmapCenter();
        #$view->vars['map_position'] = $dbrow->getGmapPosition();
        #$view->vars['map_zoomlevel'] = $dbrow->getGmapZoomlevel();
    }

    public function getParent() {
        return 'text';
    }

    public function getName() {
        return 'googlemap';
    }

}

Any suggenstions to get the children field with 3 fields to work?

Thank you

Claus


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »