fix: validate owner/repo split in create_issue.html before submission
Add client-side validation to ensure a repository is selected before form submission. Split owner/repo on both change and submit events. Show inline error messages via form-error div. Update CreateIssue handler to return HTMX-friendly HTML error fragments on 400/500. Closes leeworks-agents/gitea-mobile#30 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -493,6 +493,12 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
body := r.FormValue("body")
|
||||
|
||||
if owner == "" || repo == "" || title == "" {
|
||||
if isHTMX(r) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
fmt.Fprint(w, `<span class="empty">owner, repo, and title are required</span>`)
|
||||
return
|
||||
}
|
||||
http.Error(w, "owner, repo, and title are required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -500,6 +506,12 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
issue, err := h.Client.CreateIssue(r.Context(), token, owner, repo, title, body, nil)
|
||||
if err != nil {
|
||||
slog.Error("failed to create issue", "error", err)
|
||||
if isHTMX(r) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprint(w, `<span class="empty">Failed to create issue. Please try again.</span>`)
|
||||
return
|
||||
}
|
||||
http.Error(w, "failed to create issue", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user