コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $autocomplete = new Autocomplete();
     if ($options['prefix'] !== null) {
         $autocomplete->setPrefixJavascriptVariable($options['prefix']);
     }
     if ($options['bound'] !== null) {
         if (is_array($options['bound'])) {
             call_user_func_array(array($autocomplete, 'setBound'), $options['bound']);
         } else {
             $autocomplete->setBound($options['bound']);
         }
     }
     if (!empty($options['types'])) {
         $autocomplete->setTypes($options['types']);
     }
     if (!empty($options['component_restrictions'])) {
         $autocomplete->setComponentRestrictions($options['component_restrictions']);
     }
     if ($options['attr']) {
         foreach ($options['attr'] as $name => $value) {
             $autocomplete->setInputAttribute($name, $value);
         }
     }
     $autocomplete->setAsync($options['async']);
     $autocomplete->setLanguage($options['language']);
     $builder->setAttribute('autocomplete', $autocomplete);
 }
コード例 #2
0
 /**
  * @expectedException \Ivory\GoogleMap\Exception\PlaceException
  * @expectedExceptionMessage The asynchronous load of a place autocomplete must be a boolean value.
  */
 public function testAsyncWithInvalidValue()
 {
     $this->autocomplete->setAsync('foo');
 }
コード例 #3
0
    public function testRenderJavascriptsWithAsync()
    {
        $autocomplete = new Autocomplete();
        $autocomplete->setJavascriptVariable('autocomplete');
        $autocomplete->setAsync(true);
        $expected = <<<EOF
<script type="text/javascript">
function load_ivory_google_place () {
autocomplete = new google.maps.places.Autocomplete(document.getElementById('place_input'), {});
}
</script>
<script type="text/javascript">
function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"libraries=places&language=en","callback":load_ivory_google_place}); };
</script>
<script type="text/javascript" src="//www.google.com/jsapi?callback=load_ivory_google_map_api"></script>

EOF;
        $this->assertSame($expected, $this->autocompleteHelper->renderJavascripts($autocomplete));
    }
コード例 #4
0
ファイル: MapService.php プロジェクト: thewulf7/friendloc
 /**
  * Get autocomplete form
  *
  * @param null $value
  *
  * @return mixed
  * @throws \Ivory\GoogleMap\Exception\AssetException
  * @throws \Ivory\GoogleMap\Exception\PlaceException
  * @throws \Ivory\GoogleMap\Exception\TemplatingException
  */
 public function getAutocomplete($value = null) : array
 {
     $autocomplete = new Autocomplete();
     $autocompleteHelper = new AutocompleteHelper();
     $autocomplete->setPrefixJavascriptVariable('location_autocomplete_');
     $autocomplete->setInputId('location_input');
     $autocomplete->setInputAttributes(['class' => 'form-control', 'name' => 'locationName', 'required' => 'required']);
     $autocomplete->setInputAttribute('value', $value);
     $autocomplete->setJavascriptVariable('location_autocomplete');
     $autocomplete->setTypes([AutocompleteType::GEOCODE]);
     $autocomplete->setAsync(true);
     $autocomplete->setLanguage('en');
     $js = str_replace('load_ivory_google_map_api', 'load_ivory_google_map_api_auto', $autocompleteHelper->renderJavascripts($autocomplete));
     return ['html' => $autocompleteHelper->renderHtmlContainer($autocomplete), 'js' => $this->removeJsCaller($js)];
 }