Filter related field dropdown based on the selection of other field #558
Unanswered
umairahmed515
asked this question in
Q&A
Replies: 2 comments
-
Hi @jowilf could you please provide some assistance in this regard. Thanks |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can create a custom form for the pole field and include your own JavaScript code. class PoleField(StringField):
form_template: str = 'custom_form.html'
def additional_js_links(self, request: Request, action: RequestAction):
if action.is_form():
return ['custom_form.js']
return []
class SpanView(ModelView):
fields = [
...,
PoleField("pole"),
...
]
additional_js_links = [] In your registerFieldInitializer(function (element) {
$('#deployment', element).onchange(...)
} Make sure to place Note: This is just a guiding example, and the code is incomplete. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi @jowilf and other guys,
First of all thanks for building this tool, it really fulfils most of the requirements one can have on the admin panel.
I wanted to ask about a scenario, so I have this model:
And, I have this view class:
Screenshot:
Question:
I want to filter poles in the dropdown based on the deployment selection. So, if a user selects deployment 1, the poles dropdown should only show the poles associated with deployment 1, if user selected deployment 2, the poles dropdown should only return the poles associated with deployment 2. How can I achieve that?
The poles dropdown should only be shown once the deployment is selected, or the poles dropdown should remain disabled until deployment is selected.
Looking forward to the response. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions