Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
- {
- // come code here ....
- // TODO: Implement formElement() method.
- $element['country_id'] = [
- '#type' => 'select',
- '#title' => t('Select a country'),
- '#options' => PalomGeo::getCountryList(),
- '#default_value' => $country_id,
- '#ajax' => [
- 'callback' => '::changeCountry',
- ]
- ];
- $regions = PalomGeo::getRegionList($country_id);
- if ($regions!=[]){
- $element['region_id'] = [
- '#type' => 'select',
- '#title' => t('Select a region'),
- '#options' => $regions,
- '#default_value' => $region_id,
- ];
- }
- return $element;
- }
- // Some code here
- public function changeCountry(array &$form, FormStateInterface $form_state){
- return $form['region_id'];
- }
Add Comment
Please, Sign In to add comment