Jump to content

Remove required "City" field in address if country is "Singapore"


barefists

Recommended Posts

Hi all,

 

My shop is based in Singapore - addresses in my country do not have a "City" or "State" field in them. State is of course, already disabled via the switch in the backoffice, but I can't find a way to remove the required "City" field if the country selected is "Singapore". Please help.

 

Best Regards,
XM

Edited by barefists (see edit history)
Link to comment
Share on other sites

jgamio,

 

I think he wants to dynamically remove the city input field when country == Singapore is selected, just like the State fields pops up/hides when a country with States is (un)selected.

 

 

 

barefists, to do this:

 

Edit file:  

 

 

themes/<your theme folder>/js/tools/statesManagement.js  (Make backup!!)

and add this red piece of code to the end of the file:

 

 

function updateCity()
{
  var idCountry = parseInt($('#id_country').val());
  if (idCountry =="25" )   // 25 is Singapore's county ID (Check you own county list!)
  {
    $('#city').val( '\xa0' ); // add non-breakable space as city name
    $('#city').parent().fadeOut('fast');
  }
  else if ($('#city').val() == '\xa0' ) // if we come from Singapore,
                                        // re-display and clear city name. Otherwise ignore
  {
    $('#city').val('');
    $('#city').parent().fadeIn('slow');
    $('#city').parent().uniform();
    $('#city').focus();  // set focus to city, to make sure they type a new city name
  }
}
 
 
N.B. Make sure you check if in your shop Singapore's Country ID == 25. If not, change accordingly. 
 
Then, add two more red lines in the function
 
 
 
function bindStateInputAndUpdate()
{
  $('.id_state, .dni, .postcode').css({'display':'none'});
  updateState();
  updateNeedIDNumber();
  updateZipCode();
  updateCity();
 
  $(document).on('change', '#id_country', function(e)
  {
    updateState();
    updateNeedIDNumber();
    updateZipCode();
    updateCity();
  });
...
 
 
 
That should do the trick. 
post-455771-0-91211700-1428861620_thumb.png
post-455771-0-65132600-1428861639_thumb.png
 
Hope this helps.
pascal
Edited by PascalVG (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...