Some countries don't have states, breaks state ajax

Create issue
Issue #1119 resolved
Alex Robbins created an issue

Aland Islands, as well as others, doesn't have any states. This makes the ajax view return an empty select box, which looks a little weird.

I attached a diff that replaces the dropdown with a text input in this case. If a new country is picked with states the text input turns back into a select dropdown. (The js gets a little more complicated, but I don't think it is too bad.)

Let me know if the patch needs improvement.

Thanks, Alex

Comments (13)

  1. Tay Ray Chuan

    Why replace the dropdown with a text input when there are no states? Is this so that the user can enter the state? But in the first place, there aren't any states - unless, that is, we have flawed data.

  2. Tay Ray Chuan

    I can think of two things we could do:

    1. Display a single option, "--Please Select--".
    2. Hide the whole state row.
  3. Alex Robbins reporter

    I figured making it a text input box gives the user maximum options. If we do have wrong data, no problem. If they don't have a state, just leave it empty, no worries.

    I think displaying a single option "Please Select", when there are no options would be confusing.

    Hiding the whole state row makes sense to me. Want me to write up a patch to do that?


  4. Alex Robbins reporter

    Oh, just remembered why I didn't hide the state row. Right now the code makes very few assumptions about the DOM (other than form element names, which seems reasonable). If we try to hide the state row we need to get the input, the label, and any wrapper divs that exist. That would be easy enough if we only support the satchmo template, but we'd be possibly breaking this function for people with custom templates.

    Maybe we could just add another js callback at this point, then hide the row in the default callback. If someone had a custom template, they could override the "no states" default callback with their own function that handled their specific template.

    Thanks for your work on this, ajax state population was a huge need!


  5. Tay Ray Chuan

    Hmm, how about "Not applicable"?

    For hiding of the row - users might have a different template and consequently a different DOM, so I think it's best the user do this themselves. You can do this by hooking onto satchmo.on_state_load and/or satchmo.on_ship_state_load; look at the template /contact/_state_js.html for more details.

  6. Chris Moffitt repo owner

    FWIW, I agree that the "Not Applicable" approach sounds best. So, are we saying we'd just automatically return "Not Applicable" if we can't find any states? Sounds like the simplest solution.

  7. Tay Ray Chuan

    Yeah. Users can just write a JavaScript function and hook it to the callbacks provided to hide the row if there's only one item ("Not applicable").

  8. Log in to comment