Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

"auto_choose=False" is not working #242

Closed
fuatu opened this issue Dec 1, 2017 · 4 comments · Fixed by #250
Closed

"auto_choose=False" is not working #242

fuatu opened this issue Dec 1, 2017 · 4 comments · Fixed by #250

Comments

@fuatu
Copy link

fuatu commented Dec 1, 2017

	tur= models.CharField(max_length=20, verbose_name="Tür",choices=TUR_CHOICES)
	borc = ChainedForeignKey(
		Borc, chained_field = 'tur',  chained_model_field = 'tur', blank=True, null=True,
		show_all=False, auto_choose=False, sort=True, 
		verbose_name="Borc",related_name="borc")

Even auto_choose is false when there is one record it selects the record automatically both in template and in django admin.

@blag blag added the Bug label Dec 3, 2017
@czechmate247
Copy link

czechmate247 commented Jan 19, 2018

I don't know if this is the exact fix for this issue but I found a code modification that seems to be working for me. I changed the following function in the 'chainedfk.js' file:

$.each(j, function (index, optionData) {
       var option = $('<option></option>')
		.prop('value', optionData.value)
		.text(optionData.display);
	if (auto_choose || init_value && optionData.value == init_value) {
		option.prop('selected', true);
	}
	options.push(option);
});

To the function below. I found via browser developer console that "true" or "false" would sometimes be a boolean and sometimes be a string which would change the logic for this function:

$.each(j, function (index, optionData) {
	var option = $('<option></option>')
		.prop('value', optionData.value)
		.text(optionData.display);
	if (auto_choose == "false" || auto_choose == "False"){
		auto_choose = false;
	} else if (auto_choose == "true" || auto_choose == "True"){
		auto_choose = true;
	}
	if (auto_choose || init_value && optionData.value == init_value) {
		option.prop('selected', true);
	}
	options.push(option);
});

I hope this helps the bug fixing efforts.

@blag
Copy link
Collaborator

blag commented Jan 21, 2018

@czechmate247 Thanks for the help! I've added your patch to my PR #250.

@fuatu Please check if my personal master branch fixes this for you and report back. If it does I'll merge it in (as mentioned above, please see PR #250 for progress on that) and cut a release to PyPI so you can install it easier in production. Thanks!

@czechmate247
Copy link

czechmate247 commented Jan 22, 2018 via email

@blag blag closed this as completed in #250 Feb 17, 2018
@blag
Copy link
Collaborator

blag commented Feb 26, 2018

Released to PyPI and GitHub in version 1.5.4. Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants