Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
At the moment, even if the user does not want to specify a country, one (by default Afganisthan) will be chosen automatically. How about adding a <none>
value to the drop down list of countries?
Comment | File | Size | Author |
---|---|---|---|
#190 | addressfield-default-value-fix-968112-190.patch | 4.76 KB | mibfire |
#173 | optional-2.png | 74.96 KB | bojanz |
#173 | optional-1.png | 37.41 KB | bojanz |
#158 | interdiff-153-158.txt | 881 bytes | ergophobe |
#158 | addressfield-nocountry-option-968112-158.patch | 3.6 KB | ergophobe |
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedHmm, the problem is that the elements on the form and the display of the field are address specific. If the user doesn't select a country, one has to be assumed - it should default to the site's default country perhaps. I'll have to revisit our available country settings - if only one country is available, then I suppose the country element could be hidden.
Comment #2
rszrama CreditAttribution: rszrama commentedJust to follow-up here, I did see that we're defaulting to the site's country if no default value has been set on the widget edit form yet. Also, we are relying on the existence of a country for the field, so not selecting one is not an option. We could still consider whether or not there should be a default "none" value that requires customers to select a country, but I'm not really sure how helpful that would be or what it would then look like for the default form presentation...
Comment #3
scor CreditAttribution: scor commentedCore provides the option
- None -
in the "Default country" list.Comment #4
jcarlson34 CreditAttribution: jcarlson34 commentedI see that a
none
value has been added for additional addresses in #1031422: Issues with addressfield multiple fields@rszrama could using the 'drupal_process_states' javascript in D7 work as a solution for this issue? Click here to check it out. Also see the Examples module for a working demonstration of #states.
Perhaps by forcing the user to choose a country first would then trigger the correct fields and form. That would (I think) allow for a none value for a starting value and make the form more dynamic at the same time.
Comment #5
robertDouglass CreditAttribution: robertDouglass commented+1 for having a <none> option right off the bat. This detail makes the address field a required field by default, which is completely counter to many use cases, where addresses are optional.
Comment #6
BenK CreditAttribution: BenK commentedSubscribing
Comment #7
mlncn CreditAttribution: mlncn commentedMarked #1206156: Can we set the country drop down list default to "-NONE-"? as duplicate.
The ideal user experience would be for admins to be able to say that the address field is optional, but if it is used, the country is required. In this, the most common use case, the country could be filled in with a sensible default, but the module could know to throw that data out if nothing else is filled out.
Agaric pledges $200 towards that solution, but i'll buy a beverage of choice for anyone who gets in a solution that doesn't require me to hack this module!
benjamin, agaric
Comment #8
mlncn CreditAttribution: mlncn commentedSam Kottler and i will be proposing a patch that gives it an empty string key, ' -- None -- ' value option for country and explaining this new concept to addressfield in its hook_field_is_empty().
With "is empty" it should not render at all. Come to think of it i could tell the field it "is empty" if it has only a country, and i and 99% of the people using this would be happy (and happily ignorant of the meaningless default countries scattered through the field's data table).
Comment #9
mlncn CreditAttribution: mlncn commentedThis seems to be the sum total of the patch needed-- simply adds a '' => '- None -' option to all country selectors.
Comment #10
mlncn CreditAttribution: mlncn commentedImproved patch putting 'No address' as option at top of form and removing other address fields.
Comment #11
mlncn CreditAttribution: mlncn commentedBump. I don't consider this the ultimate solution, but having a default country makes . Hence we are running with this patch. What is needed for a solution to make it in?
Related: #1263316: Configurable non-empty value conditions
Comment #12
socceronly CreditAttribution: socceronly commentedI would just like it to be Country and State/Province.
I would actually like all the rest to be optional.
This would be really useful for a lot of people that don't need full addresses, but just want to classify things based on country and/or provice/state.
Comment #13
rodych CreditAttribution: rodych commentedSubscribing
Comment #14
nagiek CreditAttribution: nagiek commented+1
Comment #15
nagiek CreditAttribution: nagiek commentedAlso, the patch in #10 leaves me with an error message.
Notice: Undefined index: #handlers in addressfield_process_format_form() (line 145 of sites/all/modules/addressfield/addressfield.module).
Comment #16
nagiek CreditAttribution: nagiek commentedAlso, default value of "None" not accepted on the settings form.
Comment #17
Jax CreditAttribution: Jax commentedSubscribe
Comment #18
wesnick CreditAttribution: wesnick commentedI have been able to add an addressfield without a country by writing my own plugin. It takes the site default country as the addressfield default country, then in the format callback I added in:
Comment #19
Les LimPer rszrama's suggestion in #1, I still think hiding the country selector if only one option is available is useful, so I opened that as a separate issue: #1316788: Do not display country in address block if only one country option is available. Patch attached there.
Comment #20
Les LimEDIT: double post. Guru, stop meditating.
Comment #21
Damien Tournoud CreditAttribution: Damien Tournoud commentedRyan identified the main issue with this all the way back in #1:
So, if we make the country optional, if
None
is selected we should not output any other field, as those are country-specific to begin with.Comment #22
naught101 CreditAttribution: naught101 commentedwhy not just make a generic "any country" country, that displays all elements, in the order that is most common among all countries? Then just display that data in the same order. That wouldn't need any more than an extra country defined with a special code (XX orsomething)...
Comment #23
wamilton CreditAttribution: wamilton commentedIf anyone just needs a form with address fields and have country defaulted to 'US' and hidden, you can just do this instead of writing a plugin:
actually reading the addressfield_generate function, comments, and related functions was pretty clutch here. ;)
Comment #24
socceronly CreditAttribution: socceronly commentedI see now the Location Taxonomize module is for this. Thought I can't get it to work with Address Field...
Comment #25
Damien Tournoud CreditAttribution: Damien Tournoud commentedOk, so what about outputting the address widget in the format of the default country, when
- None -
is selected?Comment #26
naught101 CreditAttribution: naught101 commentedHrm.. it might be better to have a "none" option separate to a "country undefined" option, as this would allow quick removal of an address that's already been entered, and would also prevent all the address sub-fields appearing by default.
Are there any questions about the generic order of address components? Most (all?) countries seem to use a specific -> generic order, so something like:
Maybe?
Comment #27
phen CreditAttribution: phen commented@#25,
Sounds reasonable to me.
Comment #28
rooby CreditAttribution: rooby commented+1 for 25. That's what I was thinking exactly.
Currently when you use this field inside a field collection, you end up with an extra row in the field collection every time you save because of the non-empty country field.
Comment #29
adam_b CreditAttribution: adam_b commented+1 for 25, and I'm also having the same problem as described in 28.
Comment #30
bofrost CreditAttribution: bofrost commented#28 same problem here. We need a solution for this.
Comment #31
nirbhasa CreditAttribution: nirbhasa commentedI tried to use #23 to display a default country, but still have the widget shown so people could change it, but that didn't work out. Instead what worked was to use a form_alter on the widget element itself:
Comment #32
mototribe CreditAttribution: mototribe commentedI needed to be able to import new users into my site (using migrate) with the country "none" if the countrycode in my import DB was set to NULL.
The site default country was set to "united states".
After applying the patch a new user would get created with country "united states" even if they select "none" during signup.
Only after changing the site default country to none could I import users with "none" as the country.
Line 322 of addressfield.module does that
I would think this should get removed since you can set a default country for the address field itself.
Comment #33
miahon CreditAttribution: miahon commentedI use that module with geofield/geocoder module, we
are doing local event calendar. When we have event with address
it's working fine.
But sometimes we have also events without addresses.
Then we get wrong default value in our map (because of country field).
It is possible to hide that somehow or some other way to solve problem?
Is there NONE value to country field?
Or is it geofield issue or should I use Location module?
Comment #34
nagiek CreditAttribution: nagiek commentedMaybe what we need, instead of a "-None-" country value, is a checkbox which shows/hides the field. Kind of like how in the Date module, "All Day" shows/hides the time value.
Comment #35
klonosI think that allowing
<none>
for country will eventually cause similar issues that we are now facing with "Language neutral" - every text we write is in a certain language no matter if we store this information or not (this very text I'm writing right now is in English - unless we all speak this non-existing language called "Neutral").So, if you really think it through, you'll realize that each physical address has a country (at least it implies one) no matter if we store this information in our db or not. So we should rather:
- allow admins to set a default country for address fields
- offer the option to lock this default so it can't be changed (per field instance or content type perhaps)
- hide the field from the edit form
- *optionally* hide the address field from content display
So, the equivalent for the "Multilingual settings" tab:
...becomes our new "Address settings" tab:
Well, I haven't thought all of these options thoroughly, but you get the point ;)
Comment #36
rooby CreditAttribution: rooby commented^^^^ What he said.
That's the idea solution I think.
If you really want an address without a country just set a deafult and hide the field then hide the country value everywhere on the site.
But if you are dealing with addresses that don't have a country at all this module probably isn't for you. Just use text fields.
Comment #37
klonosAs I said, this one should be *optional* for display. There are valid use cases when the country field might be required to be pre-filled with a default value, then hidden/locked during input but still desired to be visible in display.
Comment #38
adam_b CreditAttribution: adam_b commentedSorry, I don't think the language analogy works.
I'm presently compiling a database which will include addresses. I don't know all of the addresses (not even the countries) at this point, and I may never know some of them. At the moment all I can do is specify "Afghanistan" as the default (chosen because it's first in the list and pretty unlikely to be chosen in real life). Why should I have to do this? A simple "-None-" or "-Select-" option, with the address widget displaying no fields, seems by far the simplest solution to me.
Comment #39
rooby CreditAttribution: rooby commented@adam_b:
I don't like your chances of getting a none value in.
The module is very specifically for standards based postal addresses, which must have a country.
You would likely have to implement your own address format plugin.
For a similar request see the maintainers response to #1048734: Required setting on individual fields
Comment #40
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedAnd what about, when the address field is optional, and completely not required? The user can not leave it empty, because the Country field is contains a data, and nobody can clear. So, if you leave all of other fields empty, then on the node view page the label of the field is displayed with only the name of the country. This behavior is not a good idea, because I not set this value, I posted a full empty address without any changes. In this case, the data is writed into the related table.
The default "- None -" option is a good idea, IMHO. If the user fill any of the other fields, then the country selection is required. But if all of other fields are empty, then the Country also be empty.
Comment #41
rooby CreditAttribution: rooby commentedYeah sorry, I got a bit mixed up.
- I agree with this.
Comment #42
miahon CreditAttribution: miahon commentedYes, good writing Zoltán!
I liked also those ideas:
" is a checkbox which shows/hides the field"
" *optionally* hide the address field from content display"
Is it Conditional Fields module solution for that?
Comment #43
adam_b CreditAttribution: adam_b commentedThanks for clarifying this Zoltán - yes, I was referring to situations where the address field is optional.
I agree that as soon as you enter any data in the field you need to have a country, and Klonos's language analogy does work in that case. I'm really not worried about that part - but I'm irritated at having an optional field which doesn't allow a null value.
So perhaps there are two discussions going on here? Should this thread be split?
Comment #44
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedgo to end of the addressfield\plugins\format\address.inc
comment out the last if, like this:
It was just a quick workaround. It is works without any notices or errors. - None - option added, and you can submit empty adrress. If you edit the node again, then the default value is set again, so it is just a temporary, half-solution.
I will working on this today (set the default value to empty too, test, etc), and I hope, I will provide something today, as patch.
Comment #45
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedIt is not a feature request, that is a major bug, when a field can not empty. But, it was very easy, we just have to forget using the site_default_country system variable. I have to go now for my child, but a working version already exists on my sandbox. I hope, we can set this issue to RTBC today.
Comment #46
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedThe initial version is attached, please test it. All feedbacks are welcome.
But please, do not set this issue to RTBC, because we need a new validation. If the user filled any field, but the Country field has left blank (or changed to empty), then that address will not be saved (or that will be removed in edit phrase). This is a simple data loss. I will working on this validation tomorrow.
Comment #47
klonosI see the problem here and it is specific to use cases where the address filed needs to be optional:
...if no data is entered, there should be nothing saved in the db and no address shown in display. *But*, we don't have a way to leave the country field empty no matter what. That's why in the revised issue title I state that the address field is not *really* optional.
I believe that the proposed solution to add a -none- option in the drop-down widget, so it can be set as default for such cases is the wrong approach. It breaks use cases where we need to use the "Hide the country when only one is available" option (there will always be at least two countries/entries: -none- and whichever we choose as the default).
What we should do instead of adding an extra option in the drop-down widget is to add a -none- country entry to the list of available countries. This way:
- People that want to set a default country (required address field) and hide the widget can simply keep doing things the way we do it now.
- People that want to have the address field *truly* optional so that users can leave it "empty" can select their desired country(ies) + this "special-purpose" -none- country. They can then set this as their default. Users that leave the address fields untouched will not save anything in the db unless they select a specific country (other than -none-) from the drop-down widget.
Does this satisfy both sides?
Comment #48
klonos...this of course solves the storage and UI part of the issue. There is also the requirement for both use cases to be able to hide the field from display.
When the country field is set to a default and the address is required, the "Hide the country when only one is available" setting only hides the field from the edit form. We need to either add a second option that allows us to also hide it from display, or change the behavior of the existing setting to do that too for us. (I personally like things to be as optional as possible, so I like the first solution).
When the address field is not required, people need a way to *conditionally* hide the field from display if it is empty (hide its label actually). The pin-on-the-map-even-if-no-address-is-set issue will be solved (I believe/hope so) as a "pleasant side-effect/bonus" if we manage to not save anything in the db the way I proposed in my previous comment.
So, in other words we need a way to:
a) hide the country (sub)field from display if the country is set to a default (in a required setup).
b) hide the whole address_field label if no data is entered (in an optional setup).
Does this sum the need to hide feature for both sides too?
PS: ...this feature request deserves its own separate issue anyways.
Comment #49
rooby CreditAttribution: rooby commentedI would still argue this is a bug, because non-required fields are saving values when they are left untouched.
Not that it matters either way really.
Comment #50
klonosIf the issue title was something like:
"Setting the Postal address field as optional still saves a value in the db because there is no way to have an empty country"
...then sure it could be classified as a bug. I don't really mind, but since we've figured a/the solution, setting that as the issue's title makes it feel more like a feature request. Would you settle with "task" then?? ;)
Comment #51
Zoltán Balogh CreditAttribution: Zoltán Balogh commented@klonos, We know, the general behavior of the fields: If a field is not required, and the user not set any value, then it is not storing and not displaying any data. Could you make this general Field API behavior with the Addressfield? NO, Addressfield always storing and displaying something without any user assistance. This is a major *bug*. No other way to solving this problem, only adding an empty option, and forget to using the site's default language. If a field is not required, then it's default value *must be* empty. And since all fields can be optional, no other way. It is *not* an Addressfield specific behavior, it is the main concept of the Field API.
Everything else is may be feature request, or task or anything else independent from the title and any other properties. But, until I can not save node with an optional, leaved blank field (any type), because that is saving and displaying data, then that is a *major bug*.
Comment #52
adam_b CreditAttribution: adam_b commentedCan I agree with Klonos here and repeat my suggestion: this is actually two separate issues, and this thread should be split.
Comment #53
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedOk, I submit a new issue.
Comment #54
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedThe separated issue for the really empty address field: #1443674: A not required and empty Addressfield let really empty
Comment #55
rooby CreditAttribution: rooby commentedThe title of this issue and the title of #1443674: A not required and empty Addressfield let really empty mean the same thing am I right?
Comment #56
klonos...actually, if you take a look at this issue's summary you'll see that from the beginning it was about introducing a
<none>
country entry. So if it was to split this issue, then it's only fair that we should be "leaving" this and branching off someplace else. We do not need to file a separate issue for the feature of hiding the country from display if only one country is available though, because there is one filed already: #1316788: Do not display country in address block if only one country option is availableNo need to file a new issue for solving the
<none>
country entry either. It should be solved here. I kindly asked Zoltán to "return" and continue his work here. I made it clear that nobody would object in whatever solution he comes up with as long as he makes sure that it doesn't break the current functionality (allowing us to require the address + define the default country + hide/lock it from the edit form).Comment #57
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedWell, in this case we would require to add a new checkbox to the field edit form. If:
then we will add the - None - as new option on the entity edit form, and always set this as the default value os the Addressfield. A new verifcation also required in this case, because if the user has left blank the Country field, but enter any data into other fields, then we will lost that datas in the current state. In this case we must prevent the submission with "The country is required if you entered any data to !label field." error message.
What do you think about this solution?
Comment #58
klonosThat does sound like a proper solution indeed. How about "Make country optional" for that checkbox's label?
As for the check to avoid data loss: yes, there should be a check to see if data has been entered in *any* of the address (sub)fields. As a matter of fact, that check should be in place anyways and not specifically for this issue here. If any of the fields contain any value on form save (besides
<none>
for the country), then the whole address_field should be considered non-empty and saved in the db.Comment #59
naught101 CreditAttribution: naught101 commentedI'd just like to point out out that even taking into account the removal of empty field values, there is still a potential use of address field that doesn't require a "country" field: named places not owned by any country (eg. https://en.wikipedia.org/wiki/Bir_Tawil), and (potentially) disputed territories.
I guess there's a fair chance that places like Bir Tawil don't have an operating postal service, so Address field shouldn't take any account of them. I guess something like this is actually more suited to a module that allows the input of general locations, and isn't intended solely for postal addresses (then you could also include places like the Marianas Trench, that are named, but are in international waters). But I don't know if any of the other location modules would allow that either...
Comment #60
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedThen let's dance, first try is here. I attached a patch for the addressfield.module and a new plugin for Make country optional (zipped, because .inc can not uploaded). Please test in your environment. Feedbacks are welcome.
Comment #61
adam_b CreditAttribution: adam_b commented#60 works for me, but I'm not sure about the logic.
In order to make the default country "none" and thereby make the field truly optional, you need to:
- tick the "country optional" checkbox
- save the field
- re-open the field
- select "- None -" as the default country
- save the field again
This is really convoluted, and certainly doesn't follow the usual Drupal processes.
Could I suggest this:
- there is always a "- None -" option which can be selected as the default country in the field config
- if the "country optional" checkbox *is* ticked, then the fields appear as at present, and you can save addresses with "- None -" as the country
- if the "country optional" checkbox *is not* ticked, then the other field elements don't appear unless a country is selected
Does this make sense?
Comment #62
Zoltán Balogh CreditAttribution: Zoltán Balogh commented@adam_b if you check the new chekcbox, then addressfield_optional_country_validate() function in the new plugin, clears the default country, or not? It is the only task for that function.
Comment #63
adam_b CreditAttribution: adam_b commentedHi Zoltán - no, it doesn't clear the default country for me. I have to save the field config and then re-open it to see the "None" entry.
Comment #64
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedHere, too.
Comment #65
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedThanks @adam_b for feedback. The addressfield_optional_country_validate function is called too late, just second time. I just need an other point to clear the default, if the Make country optional is checked.
Always adding the - None - option is not a good idea IMHO, because - I think -, that is breaks the current functionality.
Comment #66
adam_b CreditAttribution: adam_b commentedI'm not sure it breaks the current functionality, because anybody who's using the module at present must have selected a default country, right? The option would only appear if people went in and changed the configuration.
However, as long as changing the values doesn't take too many steps then I can live with it this way.
Comment #67
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedThen please insert one line at the end of your addressfield.module:
If with this modification it is works well, then I post a new patch.
Comment #68
Zoltán Balogh CreditAttribution: Zoltán Balogh commented@klonos said above, there is an existing "Hide the country when only one is available" option. I think, if we always add a new item to countries list, then that will breaks the existing functionality, because we always add a new "country".
Comment #69
adam_b CreditAttribution: adam_b commentedSorry, #67 doesn't seem to make any difference for me when setting up the field.
However, the display now always shows the country, even if the "country optional" checkbox is ticked.
Comment #70
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedThere is a new solution, it is works for me at first sight. I just test some cases, and make a new patch and a new plugin soon.
Comment #71
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedSecond try.
Comment #72
adam_b CreditAttribution: adam_b commentedWorks for me, thanks. When you tick "Make country optional", the "None" option doesn't appear in the default list - but if you save the config and open it again, it is there and selected. So it's not totally obvious, but it does work. Anyone else have an opinion?
Comment #73
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedYes, yes we need more feedback. A lot of websites using this module.
Comment #74
klonosOnce you have a well-tested patch that works for your case for enough people, then please ping me (or simply set the issue to RTBC) and I'll check if it doesn't break my sites and the current functionality. Then you'll really have a broadly accepted solution ;)
Comment #75
Zoltán Balogh CreditAttribution: Zoltán Balogh commented@klonos, please test it, if you have a little time. We have a possible solution, the current state is needs review. :)
Comment #76
klonosok, let me get make some time and I'll test it then.
On another note, I am following a very similar issue for the Field Collection module: #1239946: Embedded field collection items with a default value result in new items on save. So I think we should have a generic solution by changing the way core behaves with fields that are optional/required and with/without default values set for them. Here's my proposal there:
Comment #77
adam_b CreditAttribution: adam_b commentedMakes sense to me... but are you proposing this for any fields, or only for entities within a node? The former would mean a big change in the default edit-form structure.
Comment #78
klonosI'm pretty sure it might involve changes that will possibly prevent this from being done in D7 (perhaps it can live in contrib then), but I might be wrong - in fact I wish I am wrong ;)
One thing is certain though: this issue needs to be addressed in a more generic way since we are not the only module facing the same issue. Letting each module hack its own way out of this problem seems more prone to problems to me if it so happens that more than one of these modules happen to be in the same installation. Is anybody aware of any issue filed against core for what I'm proposing? I find it hard to believe that I am the one to think of this first :P
Comment #79
naught101 CreditAttribution: naught101 commentedCan that discussion please be separated out into a separate issue in the core queue?
Comment #80
Marty2081 CreditAttribution: Marty2081 commentedThe patch in #71 caused problems in our case.
We have a node type containing an unlimited field collection field with an addressfield inside and had problems with additional fields being added every time a node was edited. So we tried the patch in #71. It worked fine in the sense that no additional fields were being saved anymore when a node was edited.
However, whenever we submitted a file or imagefield change in a node (other fields in the node type), the changes were not saved and the user was returned to the edit form without any message (not even in the Drupal or Apache logs). We spent a lot of time trying to figure out what was causing this behavior and eventually found out that by reverting the patch on Addressfield we no longer have the problem.
I have no clue what the relation between the patch and the strange behaviour of submitting file field changes is.
Thanks for your work on the patch, but unfortunately it doesn't work for us.
We now use the patch from #1263316: Configurable non-empty value conditions which works for our situation.
Comment #81
Zoltán Balogh CreditAttribution: Zoltán Balogh commented@Marty2081 thank you for your feedback. I'll try to fix it when I have enough time.
Comment #82
klucid CreditAttribution: klucid commentedDoes anybody have a verdict on the patch or should I use the patch that Marty2081 linked to here: http://drupal.org/node/1263316 ?
Comment #83
adam_b CreditAttribution: adam_b commentedThis patch is working fine for me. I'm not sure that the one in #1263316: Configurable non-empty value conditions is for the same purpose.
Comment #84
Marty2081 CreditAttribution: Marty2081 commented@klucid Like adam_b says: you will have to check if the other patch is suitable for your situation. It was in our case, but it might not be in your specific case.
Comment #85
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedI am sorry, but currently I do not have enough time for this issue, I set to unassigned.
Comment #86
ryan.gibson CreditAttribution: ryan.gibson commentedThe patch in #71 worked for our use case.
Comment #87
ryan.gibson CreditAttribution: ryan.gibson commentedOh, and thanks @Zoltán Balogh.
Comment #88
bunthorne CreditAttribution: bunthorne commentedMy own use case is that I have a field for "Place of birth" and "Place of death" to be used for both historical and contemporary persons of note--who may still be alive. The simplest description of this issue is to have a "no address" option, as was described earlier, which blanks out all address field components including country. Once you actually have an address, you can make a case for needing a country.
I will try #71 to see if it works for me.
Comment #89
rooby CreditAttribution: rooby commentedPatch from #71 is working for me.
It would be better without the zip file though, that way it is easier to review & commit.
You can add the new file in your patch by doing this:
- Taken from http://drupal.org/node/707484
A couple of minor things I found were:
The plugin file name doesn't really follow the standards of the other existing ones.
It might be better named as optional-country.inc
Comment should start with a capital, end in a full stop. It also shouldn't be longer than 80 characters.
Longer than 80 characters.
Typo for chekced.
Having to save before you can select none:
I know it isn't ideal but I don't think it is that big of a deal.
It is not uncommon for you to have to reload the page to be able to select a default value based on previous selections. For example, changing the available options for a select field.
Maybe a little description could be added with the checkbox just so people know this is how it works.
Alternatively there could be some javascript added to do some fanciness for those who have it, but I don't think it is a necessity.
As to #80. I don't really know how this patch could affect file uploads.
I will test for this later.
@Marty2081:
Is it possible you have other customisations, that in combination with this patch cause issues?
Comment #90
jeffschulerBesides the "chekced" typo rooby mentioned, there's another in the next line...
I'm using Geocoder to geocode an Addressfield into a Geofield. This patch helped clear out the addressfield, but unfortunately the Geofield is maintaining its last location. Not a shortcoming of this patch, though; it's a Geocoder/Geofield issue.
Comment #91
duckzland CreditAttribution: duckzland commentedThis is the same as #71, I just merged the zip files into a single patch file.
Comment #92
duckzland CreditAttribution: duckzland commentedSorry forgot to use N in diff, here is the correct one
Comment #93
David Stosik CreditAttribution: David Stosik commentedHello,
Thanks duckzland, but the patch does not follow Drupal's community guidelines. You can find hints on how to make a patch on following pages :
If you don't use Git to create a patch (but you should !), be sure to use diff command with options -uP (unified, and include created/deleted files).
Anyways, be sure that the "diffed" folders only contain needed files (your last patch contains the previous patch file).
I rerolled the patch, based on #71 and including #89 and #90 remarks.
Regards,
David
Comment #94
duckzland CreditAttribution: duckzland commentedThanks for the update, I'll keep the guide in mind for next patch.
Comment #95
joey-santiago CreditAttribution: joey-santiago commentedPatch works, but you should move the file optional-country.inc to the directory plugins/format/ in module's dir.
thanks
Comment #96
greta_drupal CreditAttribution: greta_drupal commented[stupid, useless supposed threading] Me either. Cannot get Location Taxonomize to work with Address Field for any possible help.
Comment #97
vlkff CreditAttribution: vlkff commentedUsing of patch of #93 (same to #71) causing two issues to me:
http://drupal.org/node/1787734
http://drupal.org/node/1787744
Comment #98
David Stosik CreditAttribution: David Stosik commentedThis patch fixes optional-country.inc file's location (#95, thanks joey-santiago), but still needs work.
Comment #99
japerry#98 works for me, in terms of solving ("make addressfield completely optional by having nothing saved if -none- is selected for country")
If I select the country can be optional -- the field shows up as empty and doesn't display Afghanistan (or anything else).
Comment #100
osopolarPatch in 98 works for me.
@David Stosik: You said in #98: "but still needs work" ... may you clarify what else is needed to fix this issue?
@japerry: I think, when David Stosik says that this still needs work you can't set this to needs review (#99).
@vlkff: The related bugs you opened are bugs introduced by patches in this issue or do they already exists?
My problem why I came here was, that I use Address-Field in a user profile. The address is optionally. Users who registered on my clients site where not able to save the password, as described by vlkff in #1787744: Validation bug after node preview -- only if they filled in the password a second time. It took me a whole day or more to figure out that address field is causing this problem (the site and the profile are more complex with tons of modules involved).
Setting this issue to critical, because the sites default behavior is broken without this fix.
BTW: The patch in #98 solves my bug.
Comment #101
rszrama CreditAttribution: rszrama commentedIf the patch works, not sure why this was downgraded to "needs work." Resetting the metadata to major; it's not a critical bug if it's simply an unsupported use case. Will take a look at the patch shortly.
Comment #102
TimG1 CreditAttribution: TimG1 commentedTried patch #98 on addressfield 7.x-1.0-beta3 (2012-May-29) and 7.x-1.x-dev (2011-Dec-13). Neither worked for me. I'm supposed to see a checkbox to "Make country optional" on the addressfield edit page correct? Did I miss a step?
Drupal 7.17
Entity API 7.x-1.0-rc3+11-dev (2012-Oct-23)
By the way, why is the date stamp for beta3 more recent than the -dev version? Shouldn't the -dev always be more recent to be sure the latest changes have been rolled in?
Thanks for reading,
-Tim
Comment #103
David Stosik CreditAttribution: David Stosik commentedIf I refer to the repository viewer, both dev and beta3 point to the same commit, which was made Mon, 12 Dec 2011, that is 11 months ago.
Only the tag beta3 has been added later, I guess.
Path works like a charm form me, I just tried again.
results in
If patch applied successfully, did you try to clear caches? (You never know...)
Regards,
David
Comment #104
joelcollinsdc CreditAttribution: joelcollinsdc commentedIt seems this patch only works if the available countries filter isn't used, correct? That seems unfortunate.
Also, is it just me or is the work being done here almost completely superceded by the configuration options that are available in #1263316: Configurable non-empty value conditions? Making the country 'optional' is really just a workaround to make the field empty if only the country field is filled in?
Comment #105
alexrayu CreditAttribution: alexrayu commentedThanks, the patch is very helpful.
Comment #106
Cauliflower CreditAttribution: Cauliflower commentedPatch in #98 tested and works as expected (don't forget to enable 'Make country optional').
Comment #107
JurgenR CreditAttribution: JurgenR commentedPatch in #98 works as expected, only received a warning using beta3 version:
warning: addressfield.module has type 100755, expected 100644
Comment #108
sheldonkreger CreditAttribution: sheldonkreger commented#98 effectively makes the country optional, but if the user does not select a country, then the field for "State" disappears from both input and display. This is probably only a problem with addresses in the United States.
I believe that a valid use-case is to eliminate display of the "Country" field, but still display the "State" field on the node.
Comment #109
pfrenssen@sheldonkreger, care to explain why this is a problem? If a user would choose any other country the 'State' field would disappear too, so why shouldn't it disappear when you choose none?
If it would work the other way around, if your default country is anything other than the US it would add a 'state' field out of the blue when the user does not choose a country, that is very strange behavior.
Comment #110
mossy2100 CreditAttribution: mossy2100 commentedSorry for not reading this whole thread before posting. This solution may have already been suggested.
The site I'm currently working on is international and I don't want to have a default country. Also, with unlimited value fields, if you have a country selected by default the address is counted as not null and gets saved, which means you add a new address every time you edit and save a node, even if nothing is changed.
This was my solution:
- In hook_form_alter(), added an option array('' => '- Please select -') to the top of the #options array for the country.
- If the addressfield is new, set default_value to ''.
- In some JS/JQ, for each addressfield country selector, if it's blank remove the other addressfield fields from the page. You could also just hide them. It makes no difference because the fields are replaced via AJAX once you select a country.
- (Tricky bit) If the country is non-null then set to '', I wanted the addressfields to disappear. But an AJAX callback is triggered (haven't tried interrupting that) so I have to do some setTimeout magic to remove those fields after the AJAX returned.
Let me know if you want me to share any code.
Comment #111
Chris Graham CreditAttribution: Chris Graham commentedI know this is a really dirty workaround, but for anyone who wants a single value address field to be truly optional then you can use a hook_node_presave to alter the node before it gets saved. This of course will get a bit unwieldy if you have multiple address fields across multiple content types, but I only needed it in one content type.
Pop this code in a custom module, it basically resets the address field array when only country has been set (I also reset the location geofield I am using as it is geocoded from my address field and I don't want it showing up on maps either):
Now, obviously this is not going to work with multiple value address fields and I'm not developing a multi-lingual website which would complicate the code even more, but it is a quick workaround for the problem for an individual optional address field.
Comment #112
__cj CreditAttribution: __cj commentedWorks for me. Setting back to RTBC.
sheldonkreger - #108 - Sounds like a slight different issue.
Comment #113
johnvI've been reviewing all issues with required/optional subfields.
resuming status of this issue:
- #98 is RTBC. It adds a new 'optional country' option and appends _is_empty().
- #111 is an alternative solution for issue 1844846
But I think this issue - which is a pretty big patch - should be last in line, and might be obsolete:
1. For some cases (like #108) , you do not want to make the country optional, you want it to be hidden if only one is valid. The following issue resolves that: #1316788: Do not display country in address block if only one country option is available
#1316788-#1 resolves the widget and is committed on October 21, 2011 , áfter the creation of this issue.
#1316788-#9 resolves the formatter and is RTBC.
2. For most cases, if user does not touch the addressfield, you do not want it to be stored.
That is discussed here:
#1844846: Make Addressfield optional, (even if country is required)
#1031422: Issues with addressfield multiple fields
If both issues are addressed, #98 will 'need work', and I doubt if it is still a relevant feature request.
I'll just be bold, and set the status accordingly, and invite people to assess the other issues.
Comment #114
Qandeel CreditAttribution: Qandeel commentedHi,
I second #100 in this thread, the default behavior of resetting a password or user creation through email verification is broken because user has to submit the form twice to change his password if the country field is optional.. this is a critical issue.. need to be resolved soon.
Comment #115
Qandeel CreditAttribution: Qandeel commentedHi, the patch mentioned here http://drupal.org/node/1844846#comment-7118330 does not help me at all.. I think its an issue with the validation funciton associated with address field. Because Afghanistan is by default at the top of the list and also does not have a post code so the field gets wiped out if we save a user.. and on second attempt the password gets changed.
I am going to test the patch mentioned in this thread at #98 to make it sure this works
Comment #116
Qandeel CreditAttribution: Qandeel commentedDavid,
The patch worked fine, without any errors, what should i see in the field edit page... am i going to see a new option "Make country field optional" ???
Comment #117
giuvax CreditAttribution: giuvax commentedI know this is really ugly as workaround but I gave up finding a solution with empty saved profile because of mandatory country field. I'm tired of searching solutions.
So I decided to create a rule, and here it is:
I put two conditions just to be sure.
Comment #118
deanflory CreditAttribution: deanflory commented#98 Patch currently exhibits these results when attempting to apply to the beta4 2013-May-07 and May-08 dev versions:
patch < addressfield-nocountry_option-968112-98.patch
patching file addressfield.module
Hunk #1 succeeded at 322 (offset 8 lines).
Hunk #2 succeeded at 337 (offset 10 lines).
Hunk #3 succeeded at 358 (offset 10 lines).
Hunk #4 succeeded at 443 (offset 11 lines).
Hunk #5 FAILED at 456.
Hunk #6 succeeded at 509 (offset 18 lines).
1 out of 6 hunks FAILED -- saving rejects to file addressfield.module.rej
patching file optional-country.inc
Am I missing the actual fix in one of the 5 issues about this same simple thing?
Comment #119
fgmFWIW, this patch is not included in 7.x-1.0-beta4.
Comment #120
mlncn CreditAttribution: mlncn commentedThe patch in comment 98 is indeed reviewed and tested by the community and fixes the issue most people have, which is simply to make the whole field optional. Other improvements can come later. (The two year anniversary of my patch in comment 10 is coming up, and it still works too. I just don't want to have to reapply any patch after another security update.)
Comment #121
steinmb CreditAttribution: steinmb commentedNot sure if we are RTBC here, #113 contains some very valid opinions that we still not have addressed and
#1844846: Make Addressfield optional, (even if country is required) #40 contain a really nice summary that I encourage all followers of this tread to read, at least did I find it very useful.
Comment #122
fgmRerolled on top of 7.x-1.0-beta4, for which it no longer applied.
BTW this module would need tests, but this is another issue.
Comment #123
deggertsen CreditAttribution: deggertsen commentedI personally agree with @mlncn. Progress is important. If the patch works, it should be applied unless it causes other issues. If there are other options/features that need to be considered, they should be created as separate feature requests. If we wait until every opinion and every possible feature is considered and added to the patch, the patch will probably never be ready. Of course again, if this patch breaks something that was working before, that should indeed be fixed before the patch is applied. However, I am not aware of any problems like that with this patch, though I admit that I'm new to this issue.
Patch in #122 works great.
Comment #124
mrmikedewolf CreditAttribution: mrmikedewolf commentedHey all, I had to modify #98 in order to update to the newest version of address field. Hunk 5 was failing on account of new lines of code being added in the source.
Comment #125
colanComment #126
Yuri CreditAttribution: Yuri commentedWith the latest dev and patch #124, I don't see what has changed..still can't make country optional. Am i overlooking something?
Comment #127
fgm@Yuri: did you try #122 ? It works for me and, apparently, for @deggertsen.
Comment #128
deggertsen CreditAttribution: deggertsen commentedRight, number #122 and #124 appear to be very different patches. I'm not sure what #124 does as I have not looked into it. #122 fixes the problem in the issue title. Test it and mark RTBC if it works.
Comment #129
Martijn Houtman CreditAttribution: Martijn Houtman commented#122 with -beta4 works fine for me, solves the problem.
Comment #130
rolfmeijer CreditAttribution: rolfmeijer commentedNot sure if I do something wrong but I cannot make #122 work, not with -beta4 nor with -dev (2013-Nov-14).
I add a screenshot, as I expect, reading this thread, that I miss a checkbox in the Format Handlers.
Comment #131
guedressel CreditAttribution: guedressel commented#122 works basically. It added the "Make country optional" Checkbox in the settings. But - since my field allows unlimited values - I get a new empty address value each time I save the node.
Comment #132
guedressel CreditAttribution: guedressel commentedTurned out that the patch of #122 was missing the "_watch" element in the values-array which gets submitted during node editing.
With my patches the empty fields get detected cleanly.
I uploaded two patches: one for 7.x-1.x and one for the 1.0-beta4 release.
Comment #133
Angry Dan CreditAttribution: Angry Dan commented#132 works just fine for me.
Edit: I should probably say that I also reviewed the patch and all is fine there as well.
Comment #134
davisbenThe patch works for me as well. Here it is re-rolled against the latest dev.
Comment #135
deanflory CreditAttribution: deanflory commentedWas that against the latest dev 2013-Nov-24, or against the newer beta5 2013-Dec-06 release?
Comment #136
klonosRelated D8 core issue.
Comment #137
bmango CreditAttribution: bmango commentedI tried the patch in #134 but it would not apply cleanly to the latest dev.
Comment #138
klonosI recently came across Field Suppress. I haven't actually used the module, so I don't know in what shape it is, but from its description:
I'm not sure if or how, but the
field_suppress_blank
field setting seems that might prove useful if we used it for our cause.PS: cross-posting this to the other related issues for those that don't follow here.
Comment #139
robcarrI rolled the patch at #134 against the current beta5 release - works just fine. For some reason DEV is currently older than beta5.
As soon as the 'Make country optional' box is checked in the Field's Format Handlers (and the Field saved), then the -None- option appears in the Select list. Fantastic solution. Seen no problems yet.
I hope this patch can get committed soon.
Comment #140
MXTI can confirm that
patch provided in #134 works very well and is the best choice for me of all the following related:
Please commit this ASAP
Thank you very much for your work
Comment #141
flatfeat CreditAttribution: flatfeat commentedI too can confirm that the patch in #134 works for me, too, and solves the problem of making the address field optional. Thanks for developing this patch.
Comment #142
rolfmeijer CreditAttribution: rolfmeijer commentedFWIW, #134 works for me too, on -beta5
(just make sure you patch with -p1, so the optional-country.inc file gets placed in the plugins/format-directory, hence removed the screenshot from #130).
Comment #143
adam-delaney CreditAttribution: adam-delaney commentedI tested patch 134 against the beta5 release and it applied cleanly and resolves the issue. However this patch does not retroactively fix nodes that had empty address fields before the patch was applied.
Comment #144
steve65140 CreditAttribution: steve65140 commentedI too can confirm that the patch in #134 works for me and solves the problem of making the address field optional. Many thanks for developing this patch.
Comment #145
Elin Yordanov CreditAttribution: Elin Yordanov commented@steve65140: To subscribe please use the 'Follow' button on the upper right side of the issue pages. So that all other subscribers of the issue won't be informed about your subscription. Thanks.
Comment #146
Leeteq CreditAttribution: Leeteq commented@pc-wurm: that was not just a "subscription comment" from @steve65140, it contained a valuable confirmation that a patch works also for him, so he was right posting a comment instead of just "following" the issue.
Comment #147
Elin Yordanov CreditAttribution: Elin Yordanov commented@Leeteq, he has updated his post after mines. It was only a one-word 'Subscribing' post, otherwise I wouldn't advice him to use the 'Follow' button.
Comment #148
claudiu.cristeaIt's RTBC and good to go. Bumping!
Comment #149
jantoine CreditAttribution: jantoine commentedI updated the patch with the following changes:
I am still uncertain about the $ignore_item_keys variable and associated functionality in the addressfield_field_is_empty() function? I don't see these elements in my array.
Comment #150
Leeteq CreditAttribution: Leeteq commented#147/@pc-wurm: ah, ok, I did not pay close attention to the time stamp. Then my comment was moot.
Comment #151
ergophobe CreditAttribution: ergophobe commentedThe patch in 149 seems to be coming into play too late to make this work with geofield.
The specific problem I'm having is that an empty location nevertheless creates a geofield entry when the geofield is set to pull location from an addressfield. This creates a fatal PHP error. I'm not sure yet whether this should be considered an issue with this patch or with geofield, geophp or geocoder. But definitely applying this patch results in a fatal error
Comment #152
ergophobe CreditAttribution: ergophobe commentedI think the problem I came across in 151 is better solved on the geofield end of things.
The issue that I hae come across with the current patch that is relevant is essentially the issue highlighted by Ryan in #1 and Damien in #23, which is that ideally it would be possible to still have a default country and show the correct fields based on that or, failing that, to have it use the site default country.
This comes up for me because the addressfield module still gets Australian and New Zealand addresses wrong as per the outstanding issue here #1713698: Correct address labels for Australia for which I've offered a patch.
It seems like a better approach here would be to say that if the country is optional and only the country field has a value, that the field be considered empty, similar to how this problem is handled by https://drupal.org/project/address_empty because of #1263316: Configurable non-empty value conditions.
What are the chances that someone would have "country optional" set to true, but would consider an address consisting only of the country to be valid?
This would be an option to unsetting the default country as happens with the current patch.
Comment #153
steinmb CreditAttribution: steinmb commentedThere is also a link in my #121 comment that is worth a read.
Comment #154
ergophobe CreditAttribution: ergophobe commentedThe problem in #151 is fixed by the patch in #4 in #1992762: Programmatic Update of an entity empties a geofield due to regression introduced/exposed in issue #1777934
The other issue I mentioned is fixed (I hope) by the attached patch. Basically, this patch uses the plugin created by jantoine unchanged.
However, it also allows the admin to set the default value for the country on the field. I think it's a bad UI with the current patch in that you can change the country, but when you save it reverts to the old value and, in any case, the default setting for country on the field instance gets thrown away, so it's pretty confusing.
This patch uses the following simple logic: if the field instance has the "optional-country" flag set AND the current country on the submitted form is the same as the default country for the field instance, consider the field empty.
A further refinement would be along the lines that Damien mentioned further up, which is that if a default country is set, the "None" value would use the same settings as the default country. That would make for a nicer UI, but maybe is a different and somewhat less critical issue.
Comment #155
ergophobe CreditAttribution: ergophobe commentedPosted my patch while steinmb was posting hsi comment.
The discussion he mentions is here (#40 in #1844846: Make Addressfield optional, (even if country is required) )
The most significant suggestion there relative to this issue is that the admin be able to set which fields can be filled out and still have the field be considered empty.
The patch I submitted makes some progress toward that in that it extends the addressfield_field_is_empty() function by grabbing the field instance info so it gives access to all the field settings.
To satisfy the issue mentioned there would require adding some sort of UI (checkboxes of fields to ignore I suppose) and otherwise would be pretty easy to fold in... but it's way past my bedtime.
Also in the referenced comment, mbrakken says of the patches in this issue that
At least in my testing, my patch solves the problem of the values getting saved - that was actually the issue that got me working on this in the first place, because the existing patch was causing problems for me with geofield geocode values from addressfield.
Comment #156
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedupdated related issues
Comment #157
ergophobe CreditAttribution: ergophobe commentedJust a quick note - the work being done in #1263316: Configurable non-empty value conditions is promising, but currently it actually makes this problem worse. If one of the patches here and one of the patches there got combined, the end result would solve a lot of Addressfield issues!
Comment #158
ergophobe CreditAttribution: ergophobe commentedAdd check to make sure "optional-county" array element is not empty, causing an undefined index notice under specific circumstances.
Comment #159
Robin Millette CreditAttribution: Robin Millette commentedAs #117, I also used a rule to get rid of default adress fields. In my case, "Québec, Canada" (Québec = QC) is the default value. To remove that field value, when it's the default, I have the following, it's very explicit to make sure I don't remove other values.
Comment #160
deggertsen CreditAttribution: deggertsen commentedCould somebody who knows where we are at with this issue update the summary? I'm a bit lost as to the progress on this one and don't really want to read through all the many comments... Files need to be cleaned up as well to only show the files that are still relevant.
Thanks.
Comment #161
rooby CreditAttribution: rooby commentedAnd expanding on comment #160: #2328927: What is the current development status of this module?
Comment #162
deanflory CreditAttribution: deanflory commentedUnless someone else takes the time to combine all sorts of patches into one solution against the latest dev for D7, I'm guessing this module is dead based on the fact that most of these issues are 3-4 years old, are not fixed, and the latest release was almost a year old and didn't attempt to fix these major issues with the module (none, none selected, delete location button/allow multiple locations). I'm unable to find a solution between all the patches that don't fail when combined. The status of this module's maintenance needs to be changed. To go from the Location module in D6 to Address Field in D7 is a sure fail, tired of looping back to the same UX issues.
Comment #163
steinmb CreditAttribution: steinmb commentedRef. 160. This issue is getting long with with different pron and cons.
Comment #164
rszrama CreditAttribution: rszrama commented@deanflory This module isn't dead, fwiw. It's just complicated.
Comment #165
Yazzbe CreditAttribution: Yazzbe commentedI also rolled the patch at #134 against the current beta5 and it solves the issue.
Comment #166
andrewigman CreditAttribution: andrewigman commentedsame here, #134 with the current beta5 worked for me too.
Comment #167
deggertsen CreditAttribution: deggertsen commentedLooks like @bojanz is doing some good work on this module now with the recent commits. What do we need to test and do on this issue to get it ready to commit?
Comment #168
twooten CreditAttribution: twooten commentedI just wanted to add that the patch in #134 is working well for me with beta5. I have 8 content types, some with multiple values some with single values.
Comment #169
Bill Choy CreditAttribution: Bill Choy commentedPatch 158 ...almost works. But if you have 'Make country optional' NOT CHECKED, in the Format handlers section of manage field page, then you have a problem.
+ // @TODO - $optional_country should be a boolean to match similar settings
+ $ignore_item_keys = array('element_key', '_weight');
+ if ($optional_country && $default_country && $default_country == $item['country']) {
+ $ignore_item_keys[] = 'country';
+ }
Should be
+ // @TODO - $optional_country should be a boolean to match similar settings
+ $ignore_item_keys = array('element_key', '_weight');
+ if (($optional_country && empty($item['country'])) || ($default_country && $default_country == $item['country'])) {
+ $ignore_item_keys[] = 'country';
+ }
Comment #170
bojanz CreditAttribution: bojanz commentedI have just closed #1263316: Configurable non-empty value conditions and #1844846: Make Addressfield optional, (even if country is required) , and will be solving the optional addressfield issue here, since it's the closest in spirit to a desired solution.
Setting to a "feature request" because this is a use case addressfield never supported or was designed for.
Since there are over 200 comments in 3 issues detailing wildly different solutions to wildly different problems, I'm going to narrow it down:
Every address, at minimum MUST have a country. But, the addressfield SHOULD not need to be required.
Therefore, if the addressfield is optional, a "- None -" option should exist for the Country.
While "- None -" is selected, no other field is rendered, and nothing is entered into the database.
Once a country is selected, the rest of the widget is rendered.
Setting to "needs work" and working on a patch.
Comment #171
gmclelland CreditAttribution: gmclelland commentedWhat are your thoughts about #76.
Seems like just displaying an "Add new" button would solve all of the problems.
Pros:
- Address field wouldn't take up some much space on a node edit form. All that is displayed would be an "Add new" button.
- A Default country can be selected in the field settings
- Works for single or multivalued fields
Cons:
- It would still need a "- None -" country option (like @bojanz mentioned) for people that don't want to set a default country. -This could be split into a different issue
- It doesn't fix all the existing nodes that have empty rows saved in the database with just a country
My use cases is that I have an "event" content type where the addressfield is optional. This field is a US based. I don't want the user to have to fill in the City, State, and Zip Code. I would like those to have defaults for the City, State, Zip Code, and Country set and the Country field should be hidden because it will always be a US based address. I believe having an "Add new" button would fulfill these requirements and keep things simple.
Comment #173
bojanz CreditAttribution: bojanz commentedAnd committed:
http://cgit.drupalcode.org/addressfield/commit/?id=6371ea8
http://cgit.drupalcode.org/addressfield/commit/?id=34e3d67
Attaching screenshots of an optional single-value addressfield, on first load, and after the country change.
Also tested with multivalue fields, works fine.
I disregarded the "Add new" button because it would mean two radically different interfaces for required => TRUE and required => FALSE, and because the current implementation fits better with existing drupal UI patterns. The current implementation has the same pros & cons you listed for the button.
Comment #174
rszrama CreditAttribution: rszrama commentedHail to the king, baby.
Comment #176
deggertsen CreditAttribution: deggertsen commentedYAY! I'll finally be able to update without applying a patch. Thank you!
Comment #177
rooby CreditAttribution: rooby commentedExcellent, this has been problematic for a long time.
I really like this solution too.
Comment #178
cybermache CreditAttribution: cybermache commentedPerhaps my use needs are too simple for this awesomely complex module. I'll only be accepting addresses form the US. I liked before that I when I selected only US and the 'Hide country if only one is selected' option, the country would not be available. But now I think because the code for the hiding of the field works the way it does, it includes '- None -' as an option and therefore there are two countries and not one. So, the country is still visible in the form. Does that make sense? Is there anyway that the value '- None -' can be ignored or not identified as a country choice?
Comment #179
bojanz CreditAttribution: bojanz commentedThe module is awesomely complex because of everyone's simple needs :)
@cybermache
It's easy to hide the country if the field is required.
If you want to have both the country hidden and the field optional, you will need to invent a new UX for adding field values, possibly the one proposed in #2392033: Add an "Add new or Add address" button.
Comment #180
Revalis CreditAttribution: Revalis commentedAfter updating, I have 2 problems; one of which is mentioned by cybermache. I was only accepting US addresses with the field, but now that there is a "- None -" option available, I have a country list option that has the 2 options. And this has broken the 'hide if 1 country selected' item.
Also, my fields have become 'REQUIRED' regardless of the option being checked or not.
Comment #181
bojanz CreditAttribution: bojanz commentedAs I said, that's the intended behavior.
Open a new issue with a screenshot, and I'll try to reproduce it.
Keep in mind that if a country is selected, other fields (state, postal code, etc) will of course be required.
Comment #182
Revalis CreditAttribution: Revalis commentedThat doesn't seem very intuitive, unfortunately. And creates 'broken' behavior for the 'Hide the country when only one is available' option.
edit: I say this because, technically, you can't ever select 1 country anymore; as '- None -' is added forcibly elsewhere and not an option to exclude from the list.
That's the problem, then. Because I only have 1 country selected in the 'available countries' list. And since the addition of - None - (which I can't unselect as an option from the country list), it pre-selects 'United States' on the form, thus overriding my desire for the field to be optional.
Comment #183
bojanz CreditAttribution: bojanz commentedSee my answer in #179 for the only way to fix that.
Sounds like you might be running into #2392059: Choosing -None- still saves a row in the database, which is fixed in -dev.
I suggest updating from -rc1 to -dev, we fixed the bug there, you can switch the country from "United States" back to "- None -", thus hiding the other required fields.
Comment #184
cybermache CreditAttribution: cybermache commented@bojanz
Thanks for the quick response.
When you say
are you talking about hiding with CSS? Or is there an admin setting that I am missing.
Thanks again
Comment #185
Revalis CreditAttribution: Revalis commentedHe means that you should mark the field as a 'Required Field' (The option under the label), have 1 country selected, and select the 'Hide the country when only one is available' option.
In this use case, the select option for Country is automatically hidden. It's only when 'Required Field' is not selected, that the 'None' option is appended and creates 2 options.
Comment #186
cybermache CreditAttribution: cybermache commentedThanks @Ravalis, that did it and I think will work fine for my use case.
Comment #187
emilorol CreditAttribution: emilorol commentedThis issues is back live. Now even when not marking the field as required the fields are still required.
Comment #188
bojanz CreditAttribution: bojanz commentedI won't be responding to comments in this issue anymore. I've used it to solve what I thought the central issue is.
Open a new issue for any additional concerns or questions you might have.
Comment #190
mibfire CreditAttribution: mibfire commentedWhen "Make country optional" is set and entity is saved there is a validation error:
Notice: Undefined index: #default_value in addressfield_standard_country_validate() (line 633 of /var/www/sites/all/modules/contrib/addressfield/addressfield.module).
I created a patch to fix this.
Comment #191
rszrama CreditAttribution: rszrama at Centarro commentedReopening for review.
Comment #192
bojanz CreditAttribution: bojanz at Centarro commented#190 is a reroll of a patch I said I won't commit. Let this issue rest in peace.
Comment #193
rszrama CreditAttribution: rszrama at Centarro commentedhah, nice. : P
Comment #194
mibfire CreditAttribution: mibfire commented@bojanz, what is the problem?(I havent really read the comments about it) Why cant we solve this issue properly?
Comment #195
rszrama CreditAttribution: rszrama at Centarro commentedPlease read the thread before asking Bojan to spend time rehashing it. We don't have time to do that on issues.