下拉列表选择多个使用HTMX

发布于 2025-01-26 20:47:12 字数 668 浏览 4 评论 0原文

我正在使用django,并且我正在将一些值传递给Views.py。通过htmx,

所以我有一个下拉列表,其中有多个选择,

    <select class="custom-select mb-4" name="Wells3" multiple >
            <option selected>Select Well</option>
            {% for well in FieldWells %}
            <option value="{{well.WellID}}">{{well.WellID}}</option>
            {% endfor %}
    </select>

我选择了两个或三个选择,然后使用ctrl,然后我通过按钮发送请求,

<button class="btn btn-primary" hx-get="{% url 'Plot_Logs' %}" hx-target="#LogPlots"
hx-include="[name='Wells3']"
>Plot Logs</button>

因此,从视图中。

有什么选择吗?

非常感谢

I am using Django and I am passing some values to views.py via HTMX

So Frist I have a dropdown list with multiple choices

    <select class="custom-select mb-4" name="Wells3" multiple >
            <option selected>Select Well</option>
            {% for well in FieldWells %}
            <option value="{{well.WellID}}">{{well.WellID}}</option>
            {% endfor %}
    </select>

I selected two or three choices with Ctrl then I send the request via a button ,

<button class="btn btn-primary" hx-get="{% url 'Plot_Logs' %}" hx-target="#LogPlots"
hx-include="[name='Wells3']"
>Plot Logs</button>

so in the views.py I receive only the last value of the selection.

Are there any options to add?

Many thanks

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

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

发布评论

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

评论(2

醉梦枕江山 2025-02-02 20:47:12

您可能需要一个请求。在您的视图中列表:

这是我的模板片段 - 与您的模板片段非常相似。请注意将传递其他参数传递的hx-vals(在我的情况下从全局$商店中取出):

<select x-ref="select" multiple
        name="select_series"
        hx-include="[name='select_series']"
        hx-get="{% url 'grid_index' %}"
        hx-vals="javascript:{...get_parameters()}"
        hx-target="#grid"
        hx-indicator="#htmx-indicator">
    {% for this_series in series %}
        <option value="{{ this_series.value }}">
            {{ this_series.get_label }}
        </option>
    {% endfor %}
</select>

在我看来,我有:

select_series = request.GET.getlist('select_series', [])

不寻常的事情是request.get.get似乎可以正常工作(&amp;返回一个值)这并不是真的有帮助。

希望这会有所帮助

You probably need a request.getlist in your view:

Here's my template fragment - very similar to yours. Note the hx-vals to pass in other parameters (in my case taken out of a global $store):

<select x-ref="select" multiple
        name="select_series"
        hx-include="[name='select_series']"
        hx-get="{% url 'grid_index' %}"
        hx-vals="javascript:{...get_parameters()}"
        hx-target="#grid"
        hx-indicator="#htmx-indicator">
    {% for this_series in series %}
        <option value="{{ this_series.value }}">
            {{ this_series.get_label }}
        </option>
    {% endfor %}
</select>

In my view I have:

select_series = request.GET.getlist('select_series', [])

The unusual thing is request.GET.get appears to work fine (& returns a one value) which is not really helpful.

Hope this helps

我偏爱纯白色 2025-02-02 20:47:12

我能够获得所有值,只是在后端变化,

my_select_stuff: list = request.GET.getlist('name_of_stuff')

您以后可以迭代它

I was able to get all values just changing in the backend

my_select_stuff: list = request.GET.getlist('name_of_stuff')

you can later iterate it

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