如何自定义“多倍” SYMFONY中选择标签的属性

发布于 2025-02-01 03:27:56 字数 907 浏览 4 评论 0原文

我正在使用Symfony 4和 virtual select 插件,用于下拉插件,使用虚拟滚动”。

默认情况下,当Symfony呈现多个选择时,HTML代码看起来像这样:

<select multiple="multiple">

但是,Virtual Select似乎非常挑剔,并且只有当多个属性没有值的情况下才能正确地行为,例如:(

<select multiple>

就我而言,它知道,是“官方”语法,多=“多个”未提及 mozilla

。 :

  • 编写整个HTML本人并不实用,因为它很长(因此选择)。
  • 我尝试在JavaScript中传递“多个”选项,如所述在这里,但是如果HTML中仍然存在错误的语法的多个属性,那将没有效果。
  • 我可以替换虚拟选择,但是我不想在其他许多地方使用它,因为它已经使用了。

I'm using Symfony 4 and Virtual Select, "A javascript plugin for dropdown with virtual scroll".

By default, when Symfony renders a multiple select, the HTML code looks like this :

<select multiple="multiple">

However, Virtual Select seems very picky, and only behaves properly if the multiple attribute doesn't have a value, like this :

<select multiple>

(Which, as far as I know, is the "official" syntax, multiple="multiple" isn't mentioned by Mozilla for example.)

Is there there a way to force Symfony to use the second syntax instead of the first ?

I thought of a few workaround which wouldn't work :

  • Writing the whole HTML myself wouldn't be practical as it is very long (hence Virtual Select).
  • I tried passing the "multiple" option in Javascript as described here, but that has no effect if the the multiple attribute with the wrong syntax is still present in the HTML.
  • I could replace Virtual Select, but I would rather not as it is already used in many other places.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

开始看清了 2025-02-08 03:27:56

最后,我在JavaScript中使用了一个解决方法:

document.getElementById('select#whatever').setAttribute('multiple','');

似乎满足虚拟选择。

(然后,我不得不为虚拟选择和符号之间的其他问题堆积更多解决方法。总而言之,您可能应该避免将这两者一起使用。)

In the end I used a workaround in javascript :

document.getElementById('select#whatever').setAttribute('multiple','');

Which seems to satisfy Virtual Select.

(And then I had to pile up more workarounds for other issues between Virtual Select and Symfony. All in all, you probably should avoid using those two together.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文