-
Notifications
You must be signed in to change notification settings - Fork 468
Support for forward feedback clean for select2 #732
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
Conversation
|
Seems like I need a proper test suite for an example in the test project. |
|
Need something better that Probably the following should be done for fields that match
The latter leads to thoughts about autodiscovering fields that forward current field. |
|
I really love this feature, but I don't think it should be part of DAL. If we integrate this in DAL, it will only work for DAL fields. Such a feature could be useful for any kind of form fields, not just DAL. What do you think ? |
Field cleaning can be induced by any form field that emits But now I think the implementation should be reconsidered. Maybe we should declare feedback on the side of the field that should be cleaned (smth like "please forward Maybe sometimes i'll try to reimplement it from scratch in a more nice way. |
|
Perhaps you could add the change callback in your own project, and manually feed the feedback data attribute yourself in the mean time ? Then your project could still be using upstream dal instead of your branch ? I really don't want you to have to go over extra efforts maintaining your branch, but I see the work you did here and it's really cool. In DAL v1 and v2, we had the "add another" feature in DAL, for v3 it has been extracted in django-add-another, and took a life of its own. I highly encourage you to do that and to add support for all fields. However, I wonder if it would be better to just provide the script and let users do things like: Then, you could even derive on that and add more callbacks on field change, such as toggling a field display, ie. fieldA requires fieldB to have that value or something. |
|
Yes, probably this feature is weakly related to autocomplete. Seems like this PR should be closed. |
|
Hi @gagarski, perhaps you might want to consider django-dynamic-fields. Let me know what you think. 🎸 |
|
@jpic looks cool for me at first glance and more general than this PR. I'll try to look and play around with it later. |
Since building linked autocomplete hierarchy is a quite common case, I have added support for automatic clearing autocomplete on forward field change. To use it you should add something like
feedback=('field_to_clear1', 'field_to_clear2')to forwarded field Select2 widget arguments.Here is a form example that uses this feature:
This example is also provided in the test project.
This also works with with non-Select2 forwarded fields but for them you should explicitly pass comma-separated HTML-attribute (
data-autocomplete-light-forward-feedback="field_to_clear1,field_to_clear2").Here is an example with a standard HTML select being forwarded:
Also, some modifiers for feedback fields are supported:
$test- all fields ending with "test" are cleared on update (may be useful with formsets or prefixed forms);^test- all fields starting with "test" are cleared on update;*test- all fields containing "test" are cleared on update.Here is an example using modifiers: