Skip to content

Commit

Permalink
Document how to render validation errors inside a dialog with a form
Browse files Browse the repository at this point in the history
  • Loading branch information
judithroth committed Jun 24, 2024
1 parent dceff13 commit db179c4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lookbook/docs/patterns/05-dialogs.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit db179c4

Please sign in to comment.