Guest User

Untitled

a guest
Jul 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
  2. {
  3.  
  4. // come code here ....
  5.  
  6. // TODO: Implement formElement() method.
  7. $element['country_id'] = [
  8. '#type' => 'select',
  9. '#title' => t('Select a country'),
  10. '#options' => PalomGeo::getCountryList(),
  11. '#default_value' => $country_id,
  12. '#ajax' => [
  13. 'callback' => '::changeCountry',
  14. ]
  15. ];
  16.  
  17. $regions = PalomGeo::getRegionList($country_id);
  18.  
  19. if ($regions!=[]){
  20. $element['region_id'] = [
  21. '#type' => 'select',
  22. '#title' => t('Select a region'),
  23. '#options' => $regions,
  24. '#default_value' => $region_id,
  25. ];
  26. }
  27.  
  28. return $element;
  29. }
  30.  
  31. // Some code here
  32.  
  33. public function changeCountry(array &$form, FormStateInterface $form_state){
  34. return $form['region_id'];
  35. }
Add Comment
Please, Sign In to add comment