Free-text entry option for state

firebus - May 7, 2007 - 19:53
Project:Address field for CCK
Version:5.x-1.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:rconstantine
Status:closed
Description

Some things that would be nice to see in this module:

-a canonical list of countries that install with the module, not just USA and Canada. having international users is a pretty common use case.
-a way for users to select "other" for the state field and enter something as a free text field, or an option to have a free entry state field instead of using the drop down.
-a restrict the state drop down list to the selected country. even with just canada and us it's really unweildy with every state in there

thanks!

#1

firebus - May 7, 2007 - 20:04

ahh. i see in the comments that you can use activeselect to have the select form populate automatically.

so maybe the way to go is to display a text field if the states table is empty for the chosen country?

i'm working on a patch for this...

#2

firebus - May 7, 2007 - 22:07
Status:active» needs review

Here's a patch that is so-so.

It provides a "full text entry" option for the state formatting.
It disables the validation of entered state against the states in the database.

AttachmentSize
cck_address.module.patch 6.58 KB

#3

firebus - May 7, 2007 - 22:12
Title:Handle multiple countries» Free-text entry option for state

#4

rconstantine - May 9, 2007 - 19:56

I'll have to think about this one. Although I can see why you would want this functionality, I prefer having all of the necessary data present for both states and countries for validation purposes. Ex. for State, someone shouldn't be able to put "Your mom" and pass validation. This is why I'm working on a fairly simple template for others to create add-on modules for the countries they want to add. I'm nearly finished with the revamp of Canada. It will be the template to base other countries on. I have created a hook so that each new sub-module will be able to do its own validation.

Yes, this does pose a problem for those who don't know which countries they need to support on their site, which is why I'm not dismissing your patch, but am considering it. I'll let you know...

#5

firebus - May 9, 2007 - 21:57

I think it all depends on the use case. For me, I have a group about about 300 people that I need shipping address info for from all over the world. Humans will be validating the addresses before anything is shipped, as will the shipping software, so it's not vital for me to have the states validated.

However, it is vital for me (and others in my situation) to support many countries. There are about 250 countries in the iso 3166 country list (http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html) and it would take quite a long time to generate correct state/province lists for all countries.

I'd be happy to amend my patch to enable validation for those countries that have state data in the database, skipping it for countries without state info.

I can also provide a complete iso 3166 country list as .sql if you like.

Thanks for considering my patch!

#6

rconstantine - May 9, 2007 - 23:00

I like the additional thoughts you've had and see the need for your use case. In the admin settings, you should add a checkbox to 'Allow "other" countries' possibly placed in the same container as the "Allowed Countries". That flag will determine whether to fire the generic validator (which maybe just pulls out markup) if an 'other' country is found and will skip firing my new validation hook. Make a note in the settings page that using 'other' countries will not provide full validation for any field and so the admins should manually/visually confirm valid addresses.

In any case, I will finally get the new dev release out in a couple of hours, so think about adjusting your patch for it so I can rapidly apply it.

Thanks.

#7

firebus - May 10, 2007 - 01:02

Okay, here's an updated patch.

The state validator validates on state abbreviations. However, it think it's too hard on users to require them to enter a correct abbreviation for some countries, and whatever they want for other countries. And it would be unwieldy to list which countries will be validated and which not.

So I took the simpler route of disabling state validation (and only state validation against the states table - the rest of the validation is still enabled and i'm not completely bypassing your validation hook) when the other_countries checkbox is checked.

I don't think it makes a lot of sense, as it stands, to enable free-text entry without also checking the 'other countries' box, so probably some refinement is in order on the config page.

If this patch doesn't make the new release, I'm happy to redo my changes against the new release and resubmit, or to try things another way. Let me know what you'd like to see.

AttachmentSize
cck_address.module.othercountries.patch 6.23 KB

#8

rconstantine - May 10, 2007 - 03:48

I see you couldn't wait until Drupal's cron job ran to update the release page before rolling a new patch. I uploaded to CVS about 3 hours ago, so sometime in the next 9 hours it should be updated. Or you can grab it from CVS right now. If you could just double check when it comes out that your patch as it stands fits roughly okay with the new release, then post here and let me know. Don't worry about making a patch that works, because I'll probably just take your ideas and change them to how I'd like it to work. What I'm thinking, without looking at it, is this: to create this functionality not with a patch, but with a sub-module, just like any other country module. Then, "Other" would be a country with the 2-letter abbreviation of OT. It would have one built in state: 'other'. The module would form_alter necessary forms, but only if activated, etc. etc. It would also validate it's own fields by using my new hook.

Thanks for your work. Somehow this feature will get put into this module, so don't worry about that.

#9

firebus - May 11, 2007 - 02:42

sorry, i'm a n00b.

i suppose should download from CVS before redoing a patch? that would kind of make sense.

here's an updated patch against the new release that should work with the validation hook updates. thanks for considering this. handling the state as submodule makes a lot of sense.

AttachmentSize
cck_address.module.othercountries.20070510.patch 6.36 KB

#10

rconstantine - May 11, 2007 - 18:13

No problem about the n00b thing. I've only been at this for a couple of months myself.

Anyway, I've downloaded your patch. I'll take a look at it the first chance I get. Like I said, I may do things differently, but I can see the value of your suggestion, so expect it to be included in the next release. By that point, I suppose I'll have to update the main branch for an official 1.1 version instead of dev.

#11

rconstantine - June 8, 2007 - 04:52
Assigned to:Anonymous» rconstantine
Status:needs review» fixed

I finally got to this today. Look for a new dev release tomorrow. Made a couple of changes. First, if state is a text field, so is country. Both will bypass normal validation against the database. Since a list of all possible countries is overkill for the base module, I'll leave that up to you to implement. In that case, I would suggest doing it as a plugin module. You could have the country list in your .install file, and then hook_form_alter what you need in both the settings and the UI.

Please test the new version when you get it.

#12

Anonymous - June 22, 2007 - 05:16
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.