【发布时间】:2020-01-04 04:20:17
【问题描述】:
我在我的应用程序中使用 Django Autocomplete Light。在某些观点中,我对亲子关系有依赖选择(例如Country Cities)。
对于选择链接,我使用DAL documentation 中规定的“forward”功能,如下所示。
'country': autocomplete.ModelSelect2(url='country-autocomplete',
attrs={'style': 'width:80px', 'data-placeholder': 'Click here to select...',
'data-minimum-input-length': 2}),
'city': autocomplete.ModelSelect2(url='city-autocomplete',
forward=['country'],
attrs={'style': 'width:40px', 'data-placeholder': 'Click here to select...',
'data-minimum-input-length': 2}),
该页面运行正常,但需要注意的是,在选择城市之前没有选择国家/地区,“城市”选择字段会显示所有可用选项(以下是显示场景的图像)。
场景 1. 未填写国家/地区选项:
在这种情况下,我们可以看到所有名称中带有“lo”的城市选择都是在仅使用“城市”选择字段时生成的(无需先填充在“国家/地区”选项字段中)。
场景 2. 填写国家/地区选项:
In the second instance, when the city choice field is selected after picking up the "country" choice first, the names generated in the "city" choice field are limited to the country “英国”。
我的问题是:
有没有一种方法可以防止从子字段(此处为字段“city”)中选择,而无需先从父字段(此处为“国家/地区强>”)?如果 DAL 中没有可用的内置选项,我不反对使用 jQuery。
【问题讨论】:
-
发布您的自动完成视图
标签: jquery django django-forms django-views django-autocomplete-light