Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Document how to render validation errors inside a dialog with a form

Judith Rothf640e3a4374a
diff --git a/lookbook/docs/patterns/05-dialogs.md.erb b/lookbook/docs/patterns/05-dialogs.md.erb
index 5444a136bae..1da60e6ab5e 100644
--- a/lookbook/docs/patterns/05-dialogs.md.erb
+++ b/lookbook/docs/patterns/05-dialogs.md.erb
@@ -127,6 +127,29 @@ end
%>
```
+### Dialogs with form validations
+
+Sometimes a dialog with a form needs validations. If the form is submitted with turbo, the form can be rendered again with the validation errors within the dialog.
+In order for the dialog to not be closed, the rendering has to happen with an error response code (therefore 4xx or 5xx).
+
+```ruby
+class TestController < ApplicationControler
+ # include the helper module
+ include OpTurbo::DialogStreamHelper
+
+ # ...
+
+ def update
+ if @my_model.save
+ # ...
+ else
+ component = ComponentThatRendersAForm.new(my_model: @my_model)
+ update_via_turbo_stream(component: component, status: :bad_request)
+ end
+ respond_with_turbo_streams
+ end
+end
+```
## Special kinds of dialogs