-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Add form_attrs
support to all StreamField blocks
#13211
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
6ed096a
to
68310e3
Compare
Object.entries(attrs).forEach(([key, value]) => { | ||
element.setAttribute(key, `${value}`); | ||
}); |
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.
Do we want to add support for removing attributes, e.g. passing None
/null
as the value will remove it?
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.
Not sure!
@@ -62,6 +62,7 @@ class Meta: | |||
label = None | |||
icon = "placeholder" | |||
classname = None | |||
form_attrs = None |
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.
I'm calling the Python attribute form_attrs
instead of attrs
because despite the line above saying classname
, we decided to standardise this to form_classname
rather than classname
(see #6192 and #6470). The classname
attribute is a remnant of the old implementation that we keep for backwards-compatibility (but we haven't put it through a deprecation process so it still exists until now).
I suppose this makes sense seeing that the Python code is used for both the admin and the site's frontend, so we need to be explicit that this is only for the page editor form.
Meanwhile, it will be serialised for Telepath as attrs
, so the JS will do blockDef.meta.attrs
, similar to blockDef.meta.classname
. I think this is OK as in the JS context we're strictly dealing with Wagtail's page editor and not the site's frontend.
68310e3
to
24f6eaf
Compare
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.
One small issue with jQuery, otherwise all good!
Object.entries(attrs).forEach(([key, value]) => { | ||
element.setAttribute(key, `${value}`); | ||
}); |
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.
Not sure!
@@ -230,6 +231,8 @@ export class StreamBlock extends BaseSequenceBlock { | |||
} | |||
|
|||
this.initDragNDrop(); | |||
|
|||
setAttrs(this.container, this.blockDef.meta.attrs || {}); |
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.
I was wondering why TypeScript didn’t raise alarm balls about this. Turns out we’re inside a .js
file!
24f6eaf
to
f5e607c
Compare
Fixes #13203.
An example to test: