Needs work
Project:
Reference field option limit
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
3 May 2013 at 23:46 UTC
Updated:
25 Jul 2018 at 18:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
joachim commentedThanks! Patch works nicely if I add, say, two city fields both limited by the country field.
There's just a bit of tidying up I'd like:
I'm not too keen on a triple assignment, especially when it's such a long line! Can we build an $reference_option_limit_id variable first, then have two assignments?
I'd rather build up the parameters to the call as variables first. Again, it's a long line, and like this it's hard to see where one param ends and one starts.
This would be clearer I think:
I see what we're doing here -- only outputting the messages, if there are any, in front of the first ajax replacement.
I'm wondering though if there's a more graceful way to do it -- but not coming up with anything yet! If we have to do it this way, could we have a comment to explain what we're doing these funny manoeuvres for?
Comment #2
hefox commentedThis should address the messages part. Instead of appending it, adds a div above the triggering field and adds any messages to it. Could also do it below field, not sure which is better usability wise.
Comment #3
hefox commentedunintentionally changed a line
Comment #4
pomliane commentedWorks as expected, thanks hefox!
Comment #5
joachim commentedStill needs some of the tidying up mentioned in #1.
A few more things too...
Comments should be a full sentence with a capital. Trim whitespace here too.
These are not documented in https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h... -- what are they?
A comment here to say we're building an array of ajax commands, plus a @see to https://api.drupal.org/api/drupal/includes!ajax.inc/group/ajax_commands/7 would help future maintainability.
This could do with a mention that we're outputting the messages on the triggering element, as we can't know what changing element they refer to.
Comment #6
mazdakaps commentedHello
tried that patch above and its working . Three field one dependent to the other. Like that:
Country
Region
Town
Region dependent to Country and Town dependent to Region. When i select the Country field it limits as it should the Region field
. Also the Region field when i select a Region limits the Town field. But if i change my mind and want to select another Country it only populates the Region field but not the Town field. I could make both fields dependet to Country field but it would be great when first field changes both fields could change also not only the one.
Thank you very much
Comment #7
ryanoreilly commentedConfirming patch in #3 works.
Comment #8
nwom commented#3 worked for me as well. Thanks!
Comment #9
amorales@drupal.org.es commented#3 worked for me.... But not for required fields.
Country --> required
Region --> Not required
Town --> Not required
Any idea for solving this?
Thanks!
Comment #10
nwom commented@amorales All of my fields are required. Are you sure that the module works with just one field for you?
Comment #11
amorales@drupal.org.es commentedSorry, the module works for me the same way before and after aplying the patch
Applying the patch over 7.x-1.4 displays the following message:
Checked then the .module file and all changes were made right.
My configuration is as follow:
Taxonomies:
3 Taxonomies: Region --> City --> Area
City has one term reference: Region
Area has two reference terms: Region and City. City is checked with "Limit this field's options according to matching field values" and matching field with the region field Hiding options...
Content Type:
Added reference terms fields for Region, City and Area.
City and Area have the option for limiting the field checked, hiding option is also checked. Area field is limited with City.
Behavior:
If both 3 fields, Region, City and Area are required fields:
If I select RegionA then automatically appears CityA selected as the first option for that region, but AreaA is not displayed. I have to change to other city and select back again to CityA, then AreaA is displayed correctly. It's like being hung until I select the city field again.
If City is not required field but Region and Area are:
I select RegionA, then in the city box I have None and the cities for that region. Then when I select CityA the Area's box is updated with the areas for that city.
Comment #12
mpotter commentedOK, here is an updated version of the patch applied to the latest -dev.
I tried to incorporate the requested comments, but really, we shouldn't need to teach people how to use ajax commands here. Let's focus less on exact comment wording and get this committed. The comments can always be improved in the future, but let's not take months to make these kind of improvements.
Using this patch in Open Atrium 2 along with #1986532: Support organic groups OG reference widget.
Comment #13
mas0h commentedThe same thing with #6 happens with me. If I decide to change the region I get an error message "An illegal choice has been detected" with views.
Comment #14
pmichelazzoWorking like a charm!
Thank you for the patch
Comment #15
maxmendez commentedThanks mpotter, the patch #12 work perfectly
Comment #16
jonhattan#6,#11,#13 you want #1809338: Three fields in chain?. This issue is about two fields (second level) controlled by the same one, as in:
Comment #17
jonhattanHell, I was to mark this RTBC, but fixed coding standards in comments. I think all concerns in #1 are addressed now.
Comment #20
alauddin commented#17 patch failed...got white screen of death.
Tested #12 patch and it works...ajax option limit filters both fields B & C referencing to A.
Thank you.
Comment #21
esolano commentedHi all,
I tried patch in #12 and it works when you have several fields referencing the same one, like A -> D, B -> D, C -> D.
But when you have fields referencing others, like in a chain, it fails. Like A -> B, B -> C, C -> D.
I took the patch in #12 and made it work for both scenarios. It works for me. If someone could give it try, and add some feedback, that would be nice.
This does not fix the "An illegal choice has been detected" issue when the fields are required, and there are no options for available for one of the referenced fields.
Regards!
Comment #23
kaushashah commentedHello,
I applied the patch mentioned in #12 and it worked like charm. The only problem I am facing is when I save the node, both the field values are not getting saved up, only one of them is getting saved. Any help in this is appreciable.
Comment #24
kaushashah commentedIt got solved!!! Tried it out with fresh db and it worked. It now saves both the field value with #12 patch. Thanks mpotter
Comment #25
johnpitcairn commentedPatch at #12 applies against latest dev (2014-Aug-10) with
Hunk #4 succeeded at 521 (offset 29 lines).Works for me, with a master taxonomy reference field triggering changes in one entityreference field and one taxonomy reference field.
Comment #32
johnpitcairn commentedComment #33
johnpitcairn commented@joachim & @esolano: looks patch #21 was created from the parent directory. Let's try this one, otherwise unmodified and applies locally for me.
Comment #35
johnpitcairn commentedWorks for me but looks like the tests might need updating for this?
Comment #36
koppie commentedLooks like there were some major code changes between 1.4 and 1.5, and more with the dev version released in February. In particular looks like most of the actual ajax work was taken out of reference_option_limit_js().
Does anyone feel like re-rolling the patch against 1.5 or the latest dev? I took a hack at it but couldn't figure out where to put all the ajax stuff.
Comment #37
brunorios1 commentedAs @koppie said, patches doesn't applies anymore.
tested #12 and #33 in the last dev.
Comment #38
dariogcode commentedI have the same case described: Like A -> B, B -> C, C -> D.
And couldn't apply this patch agains the latest dev version. It appear the module doesn't use form alter anymore then I lost the path where to put the changes.
Any help is appreciated
thanks!
Comment #39
xiaodoudou commentedI did quickly fix the patch, but test are needed to confirm this one could work in all case.
I did the following case:
A --> B
A --> C
Let me know if it does cover all cases.
Comment #41
xiaodoudou commentedDid fix my patch to use git format and proper names.
Comment #42
xiaodoudou commentedComment #46
Vector- commentedMarking duplicate:
#2444851: When multiple fields source from same field, error 500 is returned in AJAX.
I liked the approach taken by the patch from @joonas.lahtinen in the above issue better than the one here, so I rerolled it with some cleanup on top of #1986532: Support organic groups OG reference widget, which seems to cover a lot of issues that might make implementing it troublesome otherwise.
This is actually the interdiff, not a proper patch, sorry.
Comment #47
Vector- commentedRebased my above patch on dev and rerolled with #1986532: Support organic groups OG reference widget applied so we can queue it for testing.
Interdiff is poorly named above.
Comment #48
Vector- commentedThis version should pass existing tests.And the interdiff against #1986532-24: Support organic groups OG reference widget.Doesn't work.
Comment #49
Vector- commentedCan we set this to Needs Review now that existing tests work, or do we need new tests too?Comment #51
Vector- commentedThat last patch missed some cleanup during the reroll.Sorry about the patch spam.Doesn't work.
Comment #52
Vector- commentedNope. This needs work still.
#1986526-47: Support one field changing 2+ fields works for me, but fails tests.
Can't seem to get the ones that pass testing to work in practice, not sure where things are going wrong here.
Comment #53
Vector- commentedThis patch requires #1986532-24: Support organic groups OG reference widget. Likely still fails tests, but might work a bit more reliably?
I added in the recursive methodology found here to better handle dependencies, and added a fix for an issue raised in #1809338: Three fields in chain?: fields being processed by ID. Since we're doing a recursive dependency check, I used the resultant stack to rebuild a processing chain that should (I think?) respect those dependencies while processing fields.
There's no circular checking so... yeah, don't do that.
PS: This still needs some cleanup - things like passing $form_state by reference for no particular reason (stuff leftover from a previous iteration of the code), replacing the trigger check with a call to add_dependencies and refactor add_dependencies to return a $match variable.
This definitely needs tests too.
Comment #54
Vector- commentedQuick update: I did a bit of digging and found that checkboxes have special handling in the tests, and it's checkboxes that are failing tests with the patch.
Also, if we hack it to work by adding back the 'wrapper' to the ajax elements and using ajax_command_insert(NULL, ...) on the first element, and ajax_command_replace on the rest, those tests should pass - or at least they do for me locally. I don't think that's the right way to fix this though - especially with what I'm doing in #53 that would be fragile at best.
My guess is using replace instead of insert is breaking the special condition handling in those checkbox tests somehow, but that's as far as I've tracked it so far, and I probably won't have time to come back to this for a few weeks at least.
Comment #55
Vector- commentedHere's the cleaned up version at least with the changes I mentioned in #53.
Still requires #1986532: Support organic groups OG reference widget.
Comment #56
Vector- commentedI feel bad for filling this thread with junk as I fail at rerolling things correctly.
Depends on #1986532-24: Support organic groups OG reference widget
Instructions for use without follow in another post, but there may be dragons down that road.
Comment #57
hochmania commented#56 worked for me, despite 1 hunk of the patch failing. Thank you @Vector!
Comment #58
Vector- commentedI'm guessing Hunk #5 failed? That's the dependency on #1986532: Support organic groups OG reference widget.
Shouldn't break anything, but that hunk failing leaves behind a couple lines that might cause warnings and clutters up the field's form data a bit. The dependency is there because I'm not sure about validation working properly in all cases without it, but haven't dug any deeper than that.
I wasn't going to bother to reroll this clean on dev until I had some time to inspect the tests further, but here's the bit that failed to change, should be around line 384 if that patch is all you applied:
Should look like this:
Or like this if you need the wrapper in the #ajax for some reason (like hacking tests to work):
Comment #59
hochmania commented@Vector-
Thanks, replacing the code with this snippet removed an error and it appears to all work correctly. I owe you a beer at Drupalcon