-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
🎛️ Replace base ExpandingFormset
functionality with Stimulus FormsetController w-formset
inc. initial adoption
#11633
base: main
Are you sure you want to change the base?
Conversation
Manage this branch in SquashTest this branch here: https://lb-featureformset-controller-i-hijkj.squash.io |
fc9c794
to
4fa1a29
Compare
ExpandingFormset
functionality to Stimulus FormsetController w-formset
inc. initial adoptionExpandingFormset
functionality with Stimulus FormsetController w-formset
inc. initial adoption
target.contains(input), | ||
); | ||
|
||
if (!deleteInput) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note. I could not easily write a unit test for this error case due to Stimulus not catching these errors.
I have manually tested this scenario though and it does correctly throw in the console without breaking the whole Controller behaviour.
{% include "wagtailadmin/permissions/includes/collection_member_permissions_form.html" with form=formset.empty_form only %} | ||
</tr> | ||
</template> | ||
|
||
<p class="add"> | ||
<button class="button bicolor button--icon" id="id_{{ formset.prefix }}-ADD" value="Add" type="button">{% icon name="plus" wrapped=1 %}{% block add_button_label %}{% endblock %}</button> | ||
<button class="button bicolor button--icon" id="id_{{ formset.prefix }}-ADD" type="button" data-action="w-formset#add">{% icon name="plus" wrapped=1 %}{% block add_button_label %}{% endblock %}</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<button class="button bicolor button--icon" id="id_{{ formset.prefix }}-ADD" type="button" data-action="w-formset#add">{% icon name="plus" wrapped=1 %}{% block add_button_label %}{% endblock %}</button> | |
<button class="button bicolor button--icon" id="id_{{ formset.prefix }}-ADD" value="Add" type="button" data-action="w-formset#add">{% icon name="plus" wrapped=1 %}{% block add_button_label %}{% endblock %}</button> |
Accidentally removed value="Add"
. I actually think we should not be setting the value on these buttons as it's not used visually and I'm pretty sure it's not used by the server.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#value
Probably an investigation for a different issue.
4fa1a29
to
dbf012b
Compare
dbf012b
to
371f6e9
Compare
Rebased after #11620 - we can now remove even more bespoke JS imports across the user group edit/create views. Yay. |
While this PR is not a fix for #11760 it's a good note that developers are expecting all features to work across ModelViewSet / Snippet views without having to think about what JS to import. Hence, I am keen to get on the task of migrating |
371f6e9
to
bbad762
Compare
Replaces the core functionality in `client/src/components/ExpandingFormset/index.js` and the Delete callbacks in other usage of the `window.buildExpandingFormset` function. Provides limitations on add/delete once the min/max have been reached but does not set up any disabling of these buttons as this is currently in the remit of `InlinePanel`. Includes a full test suite for error handling, updating inputs and nested usage which leverages Stimulus' scope management. Does not rely on any id attribute structure or wrangling. Relates to wagtail#7915
- Leverage the new Django 4.0 feature `deletion_widget` for formsets to attach data attributes and make the input a HiddenInput for existing and 'blank' forms. - Add support for data attributes used by the new Stimulus FormsetController
- Use the Wagtail admin formset mixin to adopt new data attributes on core form parts - Update the edit/create templates to put the attributes on the remaining elements - Add basic unit tests for smoke testing data attributes - Remove CSP incompatible inline scripts approach - Remove the now unused standalone static build/imports for the group edit view as this will not be needed - Ensure that the edit workflow form does not render any JS or attributes when the pages are not actually editable (workflow disabled)
- Use the Wagtail admin formset mixin to adopt new data attributes on core form parts - Update the edit/create templates to put the attributes on the remaining elements - Add basic unit tests for smoke testing data attributes - Remove CSP incompatible inline scripts approach - Remove the now unused standalone static build/imports for the group edit view as this will not be needed - Update Eslint accordingly
- window.buildExpandingFormset and using the base class `ExpandingFormset` can now be deprecated. - Move the window global setting to core.js which avoids the need to add the import in editor_js, to align with other future deprecations in core.js - Add upgrade considerations in release notes - `ExpandingFormset` is still needed for other existing usage (InlinePanel/MultipleChooserPanel) - Add additional JSDoc and updates to Eslint to advise developers that this feature is not to be used for new code
bbad762
to
147aa91
Compare
First stage of #7915
Overview
FormsetController
with the identifierw-formset
with the longer term plan for this to be used for the InlinePanel JS functionality also.wagtail.admin.forms.formsets.BaseFormSetMixin
(happy for a different name to be suggested).InlinePanel
at all.Additional notes
InlinePanel
https://docs.wagtail.org/en/stable/reference/pages/panels.html#inline-panel-events (have not documented, I thought release notes would be enough for this as it's not really used by customised code).selected
class to be ...-200 and the hidden attribute will be set after 200ms instead of the current 300. This reduces a common issue where we get the animation timing and the attribute updating out of sync causing chunky animations or confusing delays.hidden
for when a child form is deleted. This is more appropriate for the UI as the element is essentially meant to be removed.FormSet
in the Python class names, this is what Django uses.formsets.py
for the file in our admin files, again, following the Django convention.FormsetController
/w-formset
(notFormSetController
/w-form-set
) in the Javascript code for brevity and alignment with our existing set up event names on the InlinePanel code (e.g.w-formset:added
).'removed'
event vs (delete
/deleted
action/code).removed
for the event https://docs.djangoproject.com/en/5.0/ref/contrib/admin/javascript/ we use that same event name in our documentation for InlinePanel https://docs.wagtail.org/en/stable/reference/pages/panels.html#javascript-dom-eventsdelete
/deleted
in the code.removed
/removing
in the event names I hope this clarifies why.Checklist
How to test