【问题标题】:Is there a way to increase the height for TextBlock in Wagtail content panel?有没有办法增加 Wagtail 内容面板中 TextBlock 的高度?
【发布时间】:2021-11-04 05:26:48
【问题描述】:

有没有办法增加 Wagtail 内容面板中 TextBlock 的高度?我之前使用的是 RichTextBlock。但这会删除通过 JS 添加的 aos 动画(aos-animate 类被替换为 data-block-key)。

content = blocks.TextBlock(
    max_length=1000,
    help_text = 'Text for the About section. Maximum length is 1000 characters',
)

enter image description here

【问题讨论】:

    标签: wagtail wagtail-streamfield


    【解决方案1】:

    现阶段TextBlock 不支持自定义小部件,但您可以传入rows kwarg 以增加该字段的默认行(这将使其更高)。

    值得注意的是,TextBlock 字段会在您键入时自动增加高度。

    content = blocks.TextBlock(
        max_length=1000,
        rows=15,
        help_text = 'Text for the About section. Maximum length is 1000 characters',
    )
    
    

    阅读更多关于textarea 输入和rows 在这里的信息 - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea

    【讨论】:

    【解决方案2】:

    rows 方法是一个不错的、干净的折衷方案:一个优雅的解决方案。

    但是,如果您想触发 autosize() 方法以将 TextBlock 更改为输入的大小,则可以在覆盖的模板中使用此 JavaScript hack:

    <script>
    document.addEventListener('DOMContentLoaded', function() {
        var ta = document.getElementById('{{ child.id_for_label }}');
        var evt = new Event('input');
        ta.dispatchEvent(evt);
    });
    </script>
    

    您可以在此处查看示例: https://github.com/FlipperPA/wagtailcodeblock/blob/6d3a36442716155fdc29e1053033ef48a35047ca/wagtailcodeblock/templates/wagtailcodeblock/code_block_form.html#L18

    【讨论】:

    • 这应该是一个好的默认行为吗?也许值得提出一个拉取请求@FlipperPA
    • @LBBenJohnston 不错的主意,我会将这个边缘案例带回核心团队,看看他们的想法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多