Rename command controller => terminal controller and name the error class after terminal
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "input" ]
|
||||
static classes = [ "error" ]
|
||||
|
||||
// Actions
|
||||
|
||||
focus() {
|
||||
this.inputTarget.focus()
|
||||
}
|
||||
|
||||
handleSubmit(event) {
|
||||
if (event.detail.success) {
|
||||
event.target.reset()
|
||||
} else {
|
||||
this.#handleErrorResponse(event.detail.fetchResponse.response.status)
|
||||
}
|
||||
}
|
||||
|
||||
#handleErrorResponse(code) {
|
||||
if (code == 422) {
|
||||
this.element.classList.add(this.errorClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user