public function testDefaultState() { $this->assertSame('place_input', $this->autocomplete->getInputId()); $this->assertFalse($this->autocomplete->hasBound()); $this->assertFalse($this->autocomplete->hasTypes()); $this->assertFalse($this->autocomplete->hasComponentRestrictions()); $this->assertFalse($this->autocomplete->hasValue()); $this->assertSame(array('type' => 'text', 'placeholder' => 'off'), $this->autocomplete->getInputAttributes()); $this->assertFalse($this->autocomplete->isAsync()); $this->assertSame('en', $this->autocomplete->getLanguage()); }
/** * Renders the autocomplete. * * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. * * @return string The JS output. */ public function renderAutocomplete(Autocomplete $autocomplete) { $this->jsonBuilder->reset(); if ($autocomplete->hasTypes()) { $this->jsonBuilder->setValue('[types]', $autocomplete->getTypes()); } if ($autocomplete->hasBound()) { $this->jsonBuilder->setValue('[bounds]', $autocomplete->getBound()->getJavascriptVariable(), false); } if ($autocomplete->hasComponentRestrictions()) { $this->jsonBuilder->setValue('[componentRestrictions]', $autocomplete->getComponentRestrictions()); } if (!$this->jsonBuilder->hasValues()) { $this->jsonBuilder->setJsonEncodeOptions(JSON_FORCE_OBJECT); } return sprintf('%s = new google.maps.places.Autocomplete(document.getElementById(\'%s\'), %s);' . PHP_EOL, $autocomplete->getJavascriptVariable(), $autocomplete->getInputId(), $this->jsonBuilder->build()); }