Closed (fixed)
Project:
Examples for Developers
Version:
7.x-1.x-dev
Component:
AJAX Example
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
2 Aug 2011 at 10:10 UTC
Updated:
5 Feb 2017 at 18:10 UTC
Jump to comment: Most recent
Comments
Comment #1
olafkarsten commentedHi senthilkumarmca, you talk about an helper module for developers - it is an example(!). I moved your support request to the issue of the module.
Comment #2
rfayIf you put your code in a sandbox as a standalone module I'll be willing to take a look at it.
It looks like you're trying to change the options in the select *outside* the form builder function. That's the usual reason to get this sort of problem.
Comment #3
senthilmohith commentedthanks for the quick response..
I already tried using three different options function for country,state and city separately. I call this function in our builder function.For 2 level it is working, but for the 3 level it is not working.
if u can give example for three level select dropdown.
Comment #4
rfayThe dependent dropdown example in the AJAX Example is a complete example. There is nothing different between a two-level dependent dropdown and a three-level dependent dropdown.
Comment #5
senthilmohith commentedthank you very much. it works fine..
Comment #6
rfayComment #8
chrisjlock commentedSorry to post to a closed issue but I'm having similar problems. As long as I leave the 2nd select set to None I can change the first with out issue, but once the 2nd one is set changing the first throws error "An illegal choice has been detected. Please contact the site administrator." from form.inc ln 1289
Here is what I have:
Comment #9
rfayIf you were using the AJAX example as an example, you'd know that all form building happens in the form builder function (at least for the vast majority of cases, including yours). You're changing things in the callback, which is why you're having trouble.
Please use the dependent dropdown example as a model and go from there.
Comment #10
chrisjlock commentedThanks for the reply,
I have looked at the example and it is easy to follow for creating a custom form. However what can I do to alter the user_profile_form with out hacking core or overriding the function? Is there a hook I am missing that is called prior to the form build or Is my best bet to write a custom module and define a new field type that codes the allowed values?
Comment #11
rfay@clock you would use hook_form_alter() on the user form if doing this directly.
You might want to consider using something like the Addressfield module and attaching an address to the user. I haven't tried that.
Comment #12
chrisjlock commentedI'm currently using hook_form_alter(), the code is in #8. I have two node ref fields, the first a district and the 2nd a school. The school also has a District ref, I'm needing to filter the schools by district on the user form. But I receive an error when changing the district after the school has been set. I have set ['#limit_validation_errors'] = array(array('field_dist_ref')); which should only validate field_dist_ref I believe (when i do a dpm of $form_state it is the only value) but the error is on field_school.
Comment #13
rfayI think I already explained that you can't change the form in the callback.
Comment #14
senthilmohith commentedIn three level drop-down country, state and city. You have to check the second drop-down and third drop-down array values aren't empty. If array values empty means the error will occur "An illegal choice has been detected. Please contact the site administrator." from form.inc ln 1289.
Can you try this following code. This code works fine for me.
Comment #15
fayola commentedSo I can't have an input element in the callback because it any change to it won't be registered? I'm am a little confused. How else would I be able to generated a customized form, if those generated by the form ajax callbacks won't be registered?
Comment #16
rfayIf you don't use extreme care, change in the callback (which is after the form has been rebuilt) will cause validation errors. I recommend to everybody to make all functional changes in the form builder function.
Comment #17
nicodv commentedHi there, I replicated your code avoiding some conditionals but the second dropdown gets always empty, any idea why?
Comment #18
rfayThis really isn't a very good forum for support of this type (in a closed/fixed support request). Obviously we barely have enough time to fix problems with Examples, but we definitely don't have time for extra support. I strongly recommend http://drupal.stackexchange.com.
Comment #19
nicodv commentedok, sorry, I will look up there.
Thanks
Comment #20
Tapendra Singh commentedHi ,
I have two dropdowns in a "Template" content type one is node reference and second one is term reference. Node reference content type is Category and this content type is having term reference field. I want that when i will submit the node of Template content type i can choose the Category option based on Term reference field.
I have did some customization and made a module which is having this code. I am also facing the same error like "An illegal choice has been detected. Please contact the site administrator." when i select the first dropdown. The second select option shows this error.
Comment #21
alok.tripathiHi senthilmohith,
I used your code. It is working fine. Thanks.
But let say your all 3 dropdowns are populated and you change the first dropdown the second one gets changed again but the third one keeps the old record until you change the second one as well.
Any solution for that. To make the third one blank on changing the first one.
Also what is the use of
$no_js_use = FALSEComment #22
sunkathirs commentedHi senthilmohith & everyone,
I am looking same code for country and city dropdown list, But I dont know how to implement your code, Please guide me clearly, because I am new to drupal.
thanks
kathir
Comment #23
Sajjad Zaheer commentedSince Country, state and city dropdown list is a common problem many developers face in implementing it.
I have made a custom form filed that helps you solve exactly the same problem with minimal effort and with high efficiency.
Try using https://www.drupal.org/project/ajax_chain_select and let me know if your problem is solved.
Comment #24
ajay gadhavana commentedWorking fine for me thanks
Comment #25
netamity commentedYou could use http://geodata.solutions, which is a web service that allows you to paste a bit of html into your code and it all just works, with up-to-date, complete dataset and loads of extra options. It's much easier than writing all the code and maintaining the data yourself. It's just another option for people to think about