How to disable Countries without deleting them?

Hello,

How to to disable unnecessary countries without deleting them. I know that you can delete countries via the Studio->Forms->Data Items->System->Countries. Unfortunately, there is no option to disable them.

I don't want to delete them because I will need them (re-use them) by making them available again later. I just want to hide (disable) them from from the public and leave one country only across the website.

Any solution, even through the database?

Thanks

  • 325
  • More
Replies (16)
    • Heĺlo @OneEagle !

      The countries likt is taken from the .sys_form_pre_values table. It hasn't thе field like active which may control the value's visibility. So you can't hide via the Forms or Developer app. Only via the adding the RAW block which will clear the necessary select area from less values.

      • Hi @LeonidS Thanks for your reply but to be honest, what you wrote sounds like Japanese to me, specially the last part of your answer. Please could you clarify ithat part? Where to create the Raw block, what to put inside, etc?

        • Just tell me the page with form where you need to delete some countries. And the list of those countries.

          • I would like to disable those countries globably (entire site/all the pages) because I am bulding a country-specific website (localized site). I would like to disable them all and leave only one country: e.g: Unites State.  Thanks.

            • Then you'd better change this field to the hidden with the "US" value only.

              • But in Studio->Forms->Data Items->System I don't see how to change the field to hidden. Then I go to Studio->Developer->Data Items->System. Same, there is no option to hide the country field. Please would you give me a clue on how to hide the country field with the US' value only. Thanks.

                • It seems I found the easiest variant. Go to the Studio->Pages->[necessary module]->[Necessary page] and add there the RAW block with the following content:

                  <script language="javascript">

                   $(".bx-form-input-location-country option[value!='US']").remove();

                  </script>

                  • Ok. Thank you very much. I am going to give it a try and let you know. Now my question is instaed of adding it on a page per page basis, isn't there a way to add it globably? Maybe through main header injection? (just asking).

                    Also what about if I would like to leave visible 3 countries: US, CA, UK, the code above should be like this, right?

                    $(".bx-form-input-location-country option[value!='US, CA, UK']").remove();

                    Please correct me if I am wrong. Thanks

                    • No, it would be much different. Go to the Studio->Designer->Injections->Head injection area and place there the following code:

                      <script language="javascript">

                      $(document).ready(function() {

                        var oField = $(".bx-form-input-location-country");

                      $.each(['GB', 'CA', 'US'], function( iIndex, sValue ) {

                         oField.find("option[value='" + sValue + "']").val("---" + sValue);

                        });

                        oField.find("option:not([value^='---'])").remove();

                        oField.find("option").each(function(){

                         var sNew = $(this).val();

                         $(this).val(sNew.replace('---', ''));

                        });

                      });

                      </script>

                      • Hello @LeonidS ,

                        Wow, You have impressed me once again. Just brilliant!!!!! It works! Thank you so much for always being there to help as much as you can. What a great support!

                        My apologies for the delay in answering you. Too many things going on at the same time. Thanks. :)

                        • Here are some feedback. I tried both methods (Raw and Header Injection). They both work. Thank you so much. I have just noticed that there is a small thing that needs to be fixed.

                          Both methods displays a warning (small error message) after loading the page, just under the Postal Code Field. Where it was supposed to be showing this message 'Address is undefined', instead there is this red cross icon in a circle with this error message: 'Address not found'. The warning appears without even entering any informationa and even when I test the code with a single country e.g: ['US']. Maybe it's because both codes you provided above remove the 'Please select...' option in the country field (I am just guessing).

                          Please could you like to add back the 'Please Select...' option of the country field in both methods (Raw and Header Injection)? Maybe it will prevent the warning from appearing after laoding the page. Also when we have 2 or 3 countries in the list, it would be good to invite users to select one country by displaying the 'Please select...'option instead of preselecting a value for them in the country field.

                          Last but not the least, you forgot to answer my question in my previous post. What would have been the code to use in the Raw block if we were to leave 3 countries? E.g: US, CA, GB ? Like thie code below?

                          $(".bx-form-input-location-country option[value!='US, CA, GB]").remove();

                          Many Thanks

                          • THnx for the warm words! About your question about leaving only 3 countries. My answer from 18th of December here was about it. This line:

                            $.each(['GB', 'CA', 'US'], function( iIndex, sValue ) {

                            is responsible to drop all other countries from the default list. You may change it also in this way:

                            $.each(['', 'GB', 'CA', 'US'], function( iIndex, sValue ) {

                            to have the "Please select" variant too.

                            • Wow!!! you are just a genius. Thanks a lot. It works. with the 'Please select...' variant added back, the warning (Error message: Address not found) has disappeared when loading the page. Everything works fine.

                              My last question still remains unanswered. You provided the solution for the header injection (global). What about if i had to use the raw and add the code on a page per page basis to diaplay 3 countries and to add the 'Please select...' variant? How should the code you provided below look?

                              <script language="javascript">

                               $(".bx-form-input-location-country option[value!='US']").remove();

                              </script>

                              Thanks

                              • No, you need to use this solution only https://una.io/page/cmts-view?sys=bx_forum&id=8962&cmt_id=38290 place this code to the RAW block and place it before the other content.

                                • Oh yeah, got you now @LeonidS Thank you so much. It is the same code that can be used either in the Header injection or in the Raw. I thought they were differents codes. I have tried the same code using the Raw method and it works. Thx

                                  • Thank you so much @LeonidS, your solution has saved me a great deal!!!

                                    Login or Join to comment.