-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloning an autocomplete form dynamically #1352
Comments
Does it work with ModelMultipleChoiceField and a SelectMultiple widget
instead?
Le mer. 31 janv. 2024, 12:52, YasirKusay ***@***.***> a
écrit :
… Hello,
I am sorry for opening up an issue for this but I did not know where else
to ask this.
Lets say I have this form:
class PostForm:
tag = forms.ModelChoiceField(queryset=Tags.objects.all(),
required=True,
widget=autocomplete.ModelSelect2(url='tag_autocomplete', 'attrs': {'id: 'tag_1'}}))
In otherwords, it contains an autocomplete field that calls
tag_autocomplete to fetch a possible list of results from the search. (In
the actual form, there are more fields but I am trying to keep the code as
simple as possible)
I also have a view that takes the above form and renders it in a html file
like this:
<form>
{{ post_form.tag }}
<input type="submit">
<form>
How can I create a duplicate of the autocomplete field, for example, by
clicking an “Add Additional Tag” button. Normally, you can just get a
duplicate of an input element by cloning it and changing the new one’s
ID/name before appending it to the html. However, this is not possible here
as DAL does some additional rendering which adds additonal tags below the
form element (I tried to understand how it works from the documentation,
specifically the tutorial but I couldn’t).
—
Reply to this email directly, view it on GitHub
<#1352>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAXDLFJ5MU46Z32B6X3G43YRIWAPAVCNFSM6AAAAABCS5JEESVHI2DSMVQWIX3LMV43ASLTON2WKOZSGEYDSOJSGY4DINY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I prefer to keep separate autocomplete forms, rather than using a single autocomplete form. Is there another way? |
You mean like admin inline forms?
Le jeu. 1 févr. 2024, 01:02, YasirKusay ***@***.***> a écrit :
… I prefer to keep separate autocomplete forms, rather than using a single
autocomplete form. Is there another way?
—
Reply to this email directly, view it on GitHub
<#1352 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAXDLDLEH3L5WHDYYRP6SLYRLLRHAVCNFSM6AAAAABCS5JEESVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRQGIYTMNZRGY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Sorry, I meant that I would like separate autocomplete fields. |
Cloning the element should be supported, dal contains code to add a
mutation observer and initialize new fields
Le jeu. 1 févr. 2024, 09:58, YasirKusay ***@***.***> a écrit :
… Sorry, I meant that I would like separate autocomplete fields.
—
Reply to this email directly, view it on GitHub
<#1352 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAXDLEACJGIOGUS6CUGLFLYRNKMJAVCNFSM6AAAAABCS5JEESVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRQHAYTSMZUGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Could you let me know if I can do anything differently? |
Hi I just want to check in again. Could you let me know if I did anything wrong and if I can do anything differently? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I am sorry for opening up an issue for this but I did not know where else to ask this.
Lets say I have this form:
In otherwords, it contains an autocomplete field that calls tag_autocomplete to fetch a possible list of results from the search. (In the actual form, there are more fields but I am trying to keep the code as simple as possible)
I also have a view that takes the above form and renders it in a html file like this:
How can I create a duplicate of the autocomplete field, for example, by clicking an “Add Additional Tag” button. Normally, you can just get a duplicate of an input element by cloning it and changing the new one’s ID/name before appending it to the html. However, this is not possible here as DAL does some additional rendering which adds additonal tags below the form element (I tried to understand how it works from the documentation, specifically the tutorial but I couldn’t).
The text was updated successfully, but these errors were encountered: