Skip to content

Add form validation feedback in image URL builder #19

Description

@bonheur15

Problem

The image URL builder form on the landing page performs no input validation beyond checking for an empty source URL. Invalid inputs produce no visual error message.

Location: internal/web/views/landing.templ:90-143

Missing Validation

Input HTML Attribute Issue
<input type="text" id="b-src"> No required, no pattern Empty/invalid URLs silently show placeholder text
<input type="number" id="b-w" min="1" max="4096"> min/max set but no custom error Values outside range show browser default tooltip
<input type="number" id="b-q" min="1" max="100"> min/max set but no custom error Same as above

The JavaScript build() function at lines 115-143 performs no validation beyond if (!u) for empty source.

Proposed Fix

  1. Add visual error styling (red border) for invalid inputs
  2. Show inline error messages below or beside invalid fields
  3. Validate URL format before attempting to load the preview
  4. Add required attributes to mandatory fields
  5. Consider using the Constraint Validation API for custom messages

Example

function validate() {
    let valid = true;
    const src = document.getElementById("b-src");
    const w = document.getElementById("b-w");
    const q = document.getElementById("b-q");
    
    if (!src.value) {
        src.classList.add("error");
        valid = false;
    } else {
        src.classList.remove("error");
    }
    
    if (w.value && (w.value < 1 || w.value > 4096)) {
        w.classList.add("error");
        valid = false;
    } else {
        w.classList.remove("error");
    }
    
    // ... similar for q
    return valid;
}
.builder input.error {
    border-color: #d73a49;
    background: #ffeef0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions