Magento 2 How to add country and state dropdown in admin form? [duplicate]How To Add Country And State Dropdown In Admin Side in Magento2How To Add Country And State Dropdown In Admin Side in Magento2Magento 2 - State/Province dropdown and Country Dropdown in Contact formui_component form state/region field update after country select (M 2.1)How to add new country in country dropdown in magento2.2.1how to create city state country dropdown UIComponent in magento 2 admin formMagento2 How to add country and state drop down in customer account information tab and display state based on country selected in adminHow can I add State and Country attribute for customer in Admin, Magento2Magento2 : How to show country and state dropdown field in customer account information section in admin?Magento 2: admin grid form select dropdown relationshipNot getting region dropdown options after changing the country in magento 2 admin edit form

Software for validating answers from students

Why aren't rockets built with truss structures inside their fuel & oxidizer tanks to increase structural strength?

Word for an event that will likely never happen again

Is this n-speak?

Why is Python 2.7 still the default Python version in Ubuntu?

What kind of liquid can be seen 'leaking' from the upper surface of the wing of a Boeing 737-800?

Simplification of numbers

The cat exchanges places with a drawing of the cat

A torrent of foreign terms

How to take the beginning and end parts of a list with simpler syntax?

Are there really no countries that protect Freedom of Speech as the United States does?

What is the difference between 王 and 皇?

Website error: "Walmart can’t use this browser"

Why is statically linking glibc discouraged?

Is there a way to count the number of lines of text in a file including non-delimited ones?

Modeling the uncertainty of the input parameters

Can the IPA represent all languages' tones?

How to remove ambiguity: "... lives in the city of H, the capital of the province of NS, WHERE the unemployment rate is ..."?

Help, I cannot decide when to start the story

Is it possible to grow new organs through exposure to radioactivity?

Do beef farmed pastures net remove carbon emissions?

Update Office without opening an Office application

How far did Gandalf and the Balrog drop from the bridge in Moria?

My cat is a houdini



Magento 2 How to add country and state dropdown in admin form? [duplicate]


How To Add Country And State Dropdown In Admin Side in Magento2How To Add Country And State Dropdown In Admin Side in Magento2Magento 2 - State/Province dropdown and Country Dropdown in Contact formui_component form state/region field update after country select (M 2.1)How to add new country in country dropdown in magento2.2.1how to create city state country dropdown UIComponent in magento 2 admin formMagento2 How to add country and state drop down in customer account information tab and display state based on country selected in adminHow can I add State and Country attribute for customer in Admin, Magento2Magento2 : How to show country and state dropdown field in customer account information section in admin?Magento 2: admin grid form select dropdown relationshipNot getting region dropdown options after changing the country in magento 2 admin edit form






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0
















This question already has an answer here:



  • How To Add Country And State Dropdown In Admin Side in Magento2

    3 answers



I need to add Country and State Dropdown in Magento 2 admin form.
Please help me.










share|improve this question














marked as duplicate by Amit Bera magento2
Users with the  magento2 badge can single-handedly close magento2 questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Aug 2 at 5:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • please go thorough this "magento.stackexchange.com/questions/89856/…"

    – Rv Singh
    Aug 2 at 5:13

















0
















This question already has an answer here:



  • How To Add Country And State Dropdown In Admin Side in Magento2

    3 answers



I need to add Country and State Dropdown in Magento 2 admin form.
Please help me.










share|improve this question














marked as duplicate by Amit Bera magento2
Users with the  magento2 badge can single-handedly close magento2 questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Aug 2 at 5:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • please go thorough this "magento.stackexchange.com/questions/89856/…"

    – Rv Singh
    Aug 2 at 5:13













0












0








0









This question already has an answer here:



  • How To Add Country And State Dropdown In Admin Side in Magento2

    3 answers



I need to add Country and State Dropdown in Magento 2 admin form.
Please help me.










share|improve this question















This question already has an answer here:



  • How To Add Country And State Dropdown In Admin Side in Magento2

    3 answers



I need to add Country and State Dropdown in Magento 2 admin form.
Please help me.





This question already has an answer here:



  • How To Add Country And State Dropdown In Admin Side in Magento2

    3 answers







magento2 adminform country-regions dropdown-options






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 2 at 5:10









Himani TayalHimani Tayal

26714 bronze badges




26714 bronze badges





marked as duplicate by Amit Bera magento2
Users with the  magento2 badge can single-handedly close magento2 questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Aug 2 at 5:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











marked as duplicate by Amit Bera magento2
Users with the  magento2 badge can single-handedly close magento2 questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Aug 2 at 5:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Amit Bera magento2
Users with the  magento2 badge can single-handedly close magento2 questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Aug 2 at 5:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • please go thorough this "magento.stackexchange.com/questions/89856/…"

    – Rv Singh
    Aug 2 at 5:13

















  • please go thorough this "magento.stackexchange.com/questions/89856/…"

    – Rv Singh
    Aug 2 at 5:13
















please go thorough this "magento.stackexchange.com/questions/89856/…"

– Rv Singh
Aug 2 at 5:13





please go thorough this "magento.stackexchange.com/questions/89856/…"

– Rv Singh
Aug 2 at 5:13










2 Answers
2






active

oldest

votes


















0














To add Country and State Dropdown in admin form, follow below steps:



In your form Block file:




Define variables:




protected $_regionFactory;
protected $_countryFactory;



In Construction:




public function __construct(
...
MagentoDirectoryModelRegionFactory $regionFactory,
MagentoDirectoryModelConfigSourceCountry $countryFactory,
...
)
...
$this->_regionFactory = $regionFactory;
$this->_countryFactory = $countryFactory;
...




In initForm :




$countries = $this->_countryFactory->toOptionArray();

$countryData = $fieldset->addField(
'mycountry',
'select',
[
'name' => 'mycountry',
'data-form-part' => $this->getData('target_form'),
'title' => __('Country'),
'label' => __('Country'),
'value' => $partner['mycountry'],
'values' => $countries
]
);

$regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter($partner['mycountry']);
$regions = $regionCollection->toOptionArray();

$fieldset->addField(
'mystate',
'select',
[
'name' => 'mystate',
'data-form-part' => $this->getData('target_form'),
'title' => __('State'),
'label' => __('State'),
'values' => $regions,
'value' => $partner['mystate'],
]
);
$countryData->setAfterElementHtml("
<script type="text/javascript">
require([
'jquery',
'mage/template',
'jquery/ui',
'mage/translate'
],
function($, mageTemplate)
$('#edit_form').on('change', '#country_id', function(event)
$.ajax(
url : '". $this->getUrl('test/*/regionlist') . "country/' + $('#country_id').val(),
type: 'get',
dataType: 'json',
showLoader:true,
success: function(data)
$('#region_id').empty();
$('#region_id').append(data.htmlconent);

);
)


);
</script>"
);


Here $partner is the variable which contain all form data.






share|improve this answer
































    0














    Can you use below code



    <?php
    /**
    * @var MagentoDirectoryModelConfigSourceCountry
    */
    protected $_country;

    /**
    * @var MagentoDirectoryModelRegionFactory
    */
    protected $_regionFactory;

    // ... add them in __construct

    // ...

    // Add next changes in the _prepareForm method

    $countries = $this->_country->toOptionArray(false, 'US');
    $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter(
    $formData['country_id']
    );
    $regions = $regionCollection->toOptionArray();

    $fieldset->addField(
    'country_id',
    'select',
    ['name' => 'country_id', 'label' => __('Country'), 'required' => true, 'values' => $countries]
    );

    $fieldset->addField(
    'region_id',
    'select',
    ['name' => 'region_id', 'label' => __('State'), 'values' => $regions]
    );


    $this->setChild(
    'form_after',
    $this->getLayout()->createBlock('MagentoFrameworkViewElementTemplate')->setTemplate('Vendor_Module::js.phtml')
    );
    ?>

    > Vendor_Module::js.phtml

    <script>
    require([
    "jquery",
    "mage/adminhtml/form"
    ], function ($)

    var updater = new RegionUpdater($('[name=country_id]')[0], $('[name=region]')[0], $('[name=region_id]')[0],
    <?php echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
    'hide'
    );
    updater.disableRegionValidation();
    window.updater = updater;
    );
    </script>





    share|improve this answer

































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      To add Country and State Dropdown in admin form, follow below steps:



      In your form Block file:




      Define variables:




      protected $_regionFactory;
      protected $_countryFactory;



      In Construction:




      public function __construct(
      ...
      MagentoDirectoryModelRegionFactory $regionFactory,
      MagentoDirectoryModelConfigSourceCountry $countryFactory,
      ...
      )
      ...
      $this->_regionFactory = $regionFactory;
      $this->_countryFactory = $countryFactory;
      ...




      In initForm :




      $countries = $this->_countryFactory->toOptionArray();

      $countryData = $fieldset->addField(
      'mycountry',
      'select',
      [
      'name' => 'mycountry',
      'data-form-part' => $this->getData('target_form'),
      'title' => __('Country'),
      'label' => __('Country'),
      'value' => $partner['mycountry'],
      'values' => $countries
      ]
      );

      $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter($partner['mycountry']);
      $regions = $regionCollection->toOptionArray();

      $fieldset->addField(
      'mystate',
      'select',
      [
      'name' => 'mystate',
      'data-form-part' => $this->getData('target_form'),
      'title' => __('State'),
      'label' => __('State'),
      'values' => $regions,
      'value' => $partner['mystate'],
      ]
      );
      $countryData->setAfterElementHtml("
      <script type="text/javascript">
      require([
      'jquery',
      'mage/template',
      'jquery/ui',
      'mage/translate'
      ],
      function($, mageTemplate)
      $('#edit_form').on('change', '#country_id', function(event)
      $.ajax(
      url : '". $this->getUrl('test/*/regionlist') . "country/' + $('#country_id').val(),
      type: 'get',
      dataType: 'json',
      showLoader:true,
      success: function(data)
      $('#region_id').empty();
      $('#region_id').append(data.htmlconent);

      );
      )


      );
      </script>"
      );


      Here $partner is the variable which contain all form data.






      share|improve this answer





























        0














        To add Country and State Dropdown in admin form, follow below steps:



        In your form Block file:




        Define variables:




        protected $_regionFactory;
        protected $_countryFactory;



        In Construction:




        public function __construct(
        ...
        MagentoDirectoryModelRegionFactory $regionFactory,
        MagentoDirectoryModelConfigSourceCountry $countryFactory,
        ...
        )
        ...
        $this->_regionFactory = $regionFactory;
        $this->_countryFactory = $countryFactory;
        ...




        In initForm :




        $countries = $this->_countryFactory->toOptionArray();

        $countryData = $fieldset->addField(
        'mycountry',
        'select',
        [
        'name' => 'mycountry',
        'data-form-part' => $this->getData('target_form'),
        'title' => __('Country'),
        'label' => __('Country'),
        'value' => $partner['mycountry'],
        'values' => $countries
        ]
        );

        $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter($partner['mycountry']);
        $regions = $regionCollection->toOptionArray();

        $fieldset->addField(
        'mystate',
        'select',
        [
        'name' => 'mystate',
        'data-form-part' => $this->getData('target_form'),
        'title' => __('State'),
        'label' => __('State'),
        'values' => $regions,
        'value' => $partner['mystate'],
        ]
        );
        $countryData->setAfterElementHtml("
        <script type="text/javascript">
        require([
        'jquery',
        'mage/template',
        'jquery/ui',
        'mage/translate'
        ],
        function($, mageTemplate)
        $('#edit_form').on('change', '#country_id', function(event)
        $.ajax(
        url : '". $this->getUrl('test/*/regionlist') . "country/' + $('#country_id').val(),
        type: 'get',
        dataType: 'json',
        showLoader:true,
        success: function(data)
        $('#region_id').empty();
        $('#region_id').append(data.htmlconent);

        );
        )


        );
        </script>"
        );


        Here $partner is the variable which contain all form data.






        share|improve this answer



























          0












          0








          0







          To add Country and State Dropdown in admin form, follow below steps:



          In your form Block file:




          Define variables:




          protected $_regionFactory;
          protected $_countryFactory;



          In Construction:




          public function __construct(
          ...
          MagentoDirectoryModelRegionFactory $regionFactory,
          MagentoDirectoryModelConfigSourceCountry $countryFactory,
          ...
          )
          ...
          $this->_regionFactory = $regionFactory;
          $this->_countryFactory = $countryFactory;
          ...




          In initForm :




          $countries = $this->_countryFactory->toOptionArray();

          $countryData = $fieldset->addField(
          'mycountry',
          'select',
          [
          'name' => 'mycountry',
          'data-form-part' => $this->getData('target_form'),
          'title' => __('Country'),
          'label' => __('Country'),
          'value' => $partner['mycountry'],
          'values' => $countries
          ]
          );

          $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter($partner['mycountry']);
          $regions = $regionCollection->toOptionArray();

          $fieldset->addField(
          'mystate',
          'select',
          [
          'name' => 'mystate',
          'data-form-part' => $this->getData('target_form'),
          'title' => __('State'),
          'label' => __('State'),
          'values' => $regions,
          'value' => $partner['mystate'],
          ]
          );
          $countryData->setAfterElementHtml("
          <script type="text/javascript">
          require([
          'jquery',
          'mage/template',
          'jquery/ui',
          'mage/translate'
          ],
          function($, mageTemplate)
          $('#edit_form').on('change', '#country_id', function(event)
          $.ajax(
          url : '". $this->getUrl('test/*/regionlist') . "country/' + $('#country_id').val(),
          type: 'get',
          dataType: 'json',
          showLoader:true,
          success: function(data)
          $('#region_id').empty();
          $('#region_id').append(data.htmlconent);

          );
          )


          );
          </script>"
          );


          Here $partner is the variable which contain all form data.






          share|improve this answer













          To add Country and State Dropdown in admin form, follow below steps:



          In your form Block file:




          Define variables:




          protected $_regionFactory;
          protected $_countryFactory;



          In Construction:




          public function __construct(
          ...
          MagentoDirectoryModelRegionFactory $regionFactory,
          MagentoDirectoryModelConfigSourceCountry $countryFactory,
          ...
          )
          ...
          $this->_regionFactory = $regionFactory;
          $this->_countryFactory = $countryFactory;
          ...




          In initForm :




          $countries = $this->_countryFactory->toOptionArray();

          $countryData = $fieldset->addField(
          'mycountry',
          'select',
          [
          'name' => 'mycountry',
          'data-form-part' => $this->getData('target_form'),
          'title' => __('Country'),
          'label' => __('Country'),
          'value' => $partner['mycountry'],
          'values' => $countries
          ]
          );

          $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter($partner['mycountry']);
          $regions = $regionCollection->toOptionArray();

          $fieldset->addField(
          'mystate',
          'select',
          [
          'name' => 'mystate',
          'data-form-part' => $this->getData('target_form'),
          'title' => __('State'),
          'label' => __('State'),
          'values' => $regions,
          'value' => $partner['mystate'],
          ]
          );
          $countryData->setAfterElementHtml("
          <script type="text/javascript">
          require([
          'jquery',
          'mage/template',
          'jquery/ui',
          'mage/translate'
          ],
          function($, mageTemplate)
          $('#edit_form').on('change', '#country_id', function(event)
          $.ajax(
          url : '". $this->getUrl('test/*/regionlist') . "country/' + $('#country_id').val(),
          type: 'get',
          dataType: 'json',
          showLoader:true,
          success: function(data)
          $('#region_id').empty();
          $('#region_id').append(data.htmlconent);

          );
          )


          );
          </script>"
          );


          Here $partner is the variable which contain all form data.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 2 at 5:14









          Himani TayalHimani Tayal

          26714 bronze badges




          26714 bronze badges


























              0














              Can you use below code



              <?php
              /**
              * @var MagentoDirectoryModelConfigSourceCountry
              */
              protected $_country;

              /**
              * @var MagentoDirectoryModelRegionFactory
              */
              protected $_regionFactory;

              // ... add them in __construct

              // ...

              // Add next changes in the _prepareForm method

              $countries = $this->_country->toOptionArray(false, 'US');
              $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter(
              $formData['country_id']
              );
              $regions = $regionCollection->toOptionArray();

              $fieldset->addField(
              'country_id',
              'select',
              ['name' => 'country_id', 'label' => __('Country'), 'required' => true, 'values' => $countries]
              );

              $fieldset->addField(
              'region_id',
              'select',
              ['name' => 'region_id', 'label' => __('State'), 'values' => $regions]
              );


              $this->setChild(
              'form_after',
              $this->getLayout()->createBlock('MagentoFrameworkViewElementTemplate')->setTemplate('Vendor_Module::js.phtml')
              );
              ?>

              > Vendor_Module::js.phtml

              <script>
              require([
              "jquery",
              "mage/adminhtml/form"
              ], function ($)

              var updater = new RegionUpdater($('[name=country_id]')[0], $('[name=region]')[0], $('[name=region_id]')[0],
              <?php echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
              'hide'
              );
              updater.disableRegionValidation();
              window.updater = updater;
              );
              </script>





              share|improve this answer





























                0














                Can you use below code



                <?php
                /**
                * @var MagentoDirectoryModelConfigSourceCountry
                */
                protected $_country;

                /**
                * @var MagentoDirectoryModelRegionFactory
                */
                protected $_regionFactory;

                // ... add them in __construct

                // ...

                // Add next changes in the _prepareForm method

                $countries = $this->_country->toOptionArray(false, 'US');
                $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter(
                $formData['country_id']
                );
                $regions = $regionCollection->toOptionArray();

                $fieldset->addField(
                'country_id',
                'select',
                ['name' => 'country_id', 'label' => __('Country'), 'required' => true, 'values' => $countries]
                );

                $fieldset->addField(
                'region_id',
                'select',
                ['name' => 'region_id', 'label' => __('State'), 'values' => $regions]
                );


                $this->setChild(
                'form_after',
                $this->getLayout()->createBlock('MagentoFrameworkViewElementTemplate')->setTemplate('Vendor_Module::js.phtml')
                );
                ?>

                > Vendor_Module::js.phtml

                <script>
                require([
                "jquery",
                "mage/adminhtml/form"
                ], function ($)

                var updater = new RegionUpdater($('[name=country_id]')[0], $('[name=region]')[0], $('[name=region_id]')[0],
                <?php echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
                'hide'
                );
                updater.disableRegionValidation();
                window.updater = updater;
                );
                </script>





                share|improve this answer



























                  0












                  0








                  0







                  Can you use below code



                  <?php
                  /**
                  * @var MagentoDirectoryModelConfigSourceCountry
                  */
                  protected $_country;

                  /**
                  * @var MagentoDirectoryModelRegionFactory
                  */
                  protected $_regionFactory;

                  // ... add them in __construct

                  // ...

                  // Add next changes in the _prepareForm method

                  $countries = $this->_country->toOptionArray(false, 'US');
                  $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter(
                  $formData['country_id']
                  );
                  $regions = $regionCollection->toOptionArray();

                  $fieldset->addField(
                  'country_id',
                  'select',
                  ['name' => 'country_id', 'label' => __('Country'), 'required' => true, 'values' => $countries]
                  );

                  $fieldset->addField(
                  'region_id',
                  'select',
                  ['name' => 'region_id', 'label' => __('State'), 'values' => $regions]
                  );


                  $this->setChild(
                  'form_after',
                  $this->getLayout()->createBlock('MagentoFrameworkViewElementTemplate')->setTemplate('Vendor_Module::js.phtml')
                  );
                  ?>

                  > Vendor_Module::js.phtml

                  <script>
                  require([
                  "jquery",
                  "mage/adminhtml/form"
                  ], function ($)

                  var updater = new RegionUpdater($('[name=country_id]')[0], $('[name=region]')[0], $('[name=region_id]')[0],
                  <?php echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
                  'hide'
                  );
                  updater.disableRegionValidation();
                  window.updater = updater;
                  );
                  </script>





                  share|improve this answer













                  Can you use below code



                  <?php
                  /**
                  * @var MagentoDirectoryModelConfigSourceCountry
                  */
                  protected $_country;

                  /**
                  * @var MagentoDirectoryModelRegionFactory
                  */
                  protected $_regionFactory;

                  // ... add them in __construct

                  // ...

                  // Add next changes in the _prepareForm method

                  $countries = $this->_country->toOptionArray(false, 'US');
                  $regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter(
                  $formData['country_id']
                  );
                  $regions = $regionCollection->toOptionArray();

                  $fieldset->addField(
                  'country_id',
                  'select',
                  ['name' => 'country_id', 'label' => __('Country'), 'required' => true, 'values' => $countries]
                  );

                  $fieldset->addField(
                  'region_id',
                  'select',
                  ['name' => 'region_id', 'label' => __('State'), 'values' => $regions]
                  );


                  $this->setChild(
                  'form_after',
                  $this->getLayout()->createBlock('MagentoFrameworkViewElementTemplate')->setTemplate('Vendor_Module::js.phtml')
                  );
                  ?>

                  > Vendor_Module::js.phtml

                  <script>
                  require([
                  "jquery",
                  "mage/adminhtml/form"
                  ], function ($)

                  var updater = new RegionUpdater($('[name=country_id]')[0], $('[name=region]')[0], $('[name=region_id]')[0],
                  <?php echo $this->helper('MagentoDirectoryHelperData')->getRegionJson() ?>,
                  'hide'
                  );
                  updater.disableRegionValidation();
                  window.updater = updater;
                  );
                  </script>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 2 at 5:17









                  Soundararajan mSoundararajan m

                  569 bronze badges




                  569 bronze badges
















                      Popular posts from this blog

                      Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                      Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                      Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?