Closed Skealz closed 1 year ago
None of the code that you show suggests a problem. The can_stream()
method simply checks if the client indicated that it accepts turbo-stream responses. My guess is that this is False because your page has not loaded turbo.js. Is that possible?
When I inspect HTML, I see, in head :
<script src="https://cdn.jsdelivr.net/npm/@hotwired/turbo@7.3.0/dist/turbo.es2017-umd.js"></script>
<script>Turbo.connectStreamSource(new WebSocket(`ws${location.protocol.substring(4)}//${location.host}/turbo-stream`));</script>
Maybe I can re-check in the browser console if turbo is available, with some commands ?
I wonder if it could be something linked to the way the form is submitted, as it is submitted using select fields.
Thanks for your answer !
@Skealz I bet it is the way you submit the form, maybe it triggers a bug in turbo.js or they just don't intend to support JS submissions.
Thanks for your comments, this is indeed the way I submit the form that caused the issue. I managed to fix the issue with this code :
<form id="basic_form" method=post style="padding-top:2%;" action="{{url_submit_form}}">
{{ form.hidden_tag() }}
<div class="row" style="position: relative;">
{% for field in form if field.widget.input_type != 'hidden' %}
<div class="col s1">
{{ field.label }}
{% if form_fields_opts is defined %}
{{ field(class_="browser-default", **form_fields_opts[field.name])|safe }}
{% else %}
{{ field(class_="browser-default")|safe }}
{% endif %}
</div>
{% endfor %}
<button class="btn waves-effect waves-light blue-grey lighten-1" type="submit"
style="position: absolute; bottom: 0;">Filter</button>
</div>
</form>
<script>
$(document).ready(function() {
$('#basic_form select').change(function() {
$('#basic_form button[type=submit]').click();
});
});
</script>
There is nice Hotwire (Turbo+Stimulus) tutorial for exactly this here: https://twitter.com/ilrock__/status/1634244554462248972
It's in Rails, but can be easily used in Flask also.
Hi,
I am trying to use Turbo-Flask to update a Form (based on which value the user select in several Select fields), without updating the rest of the HTML page.
I tried using Werkzeug and also gunicorn + Nginx (I added the nginx sample config I found in the docs to Upgrade the connection).
Here is some code samples :
The form is auto-submitted when the user select a value in Select fields (onchange="this.form.submit())
turbo.can_stream or turbo.can_push are systematically False. It seems that the endpoint turbo-stream works (at least in gunicorn, sometimes in Werkzeug but it is another issue as I read on other issues)
It feels I'm doing something wrong but I don't know what.
Versions :
(I builded conda packages for flask-sock and turbo-flask)