Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Go form structs from HTML input elements #10

Open
3 of 11 tasks
crhntr opened this issue Aug 24, 2024 · 0 comments
Open
3 of 11 tasks

Generate Go form structs from HTML input elements #10

crhntr opened this issue Aug 24, 2024 · 0 comments
Labels
enhancement New feature or request html-to-go

Comments

@crhntr
Copy link
Owner

crhntr commented Aug 24, 2024

Given a form

{{define "POST /profile UpdateProfile(ctx, form)"}}
<form id="update-profile" data-go-type="Profile">
  <input type="text" name="first-name" required>
  <input type="date" name="favorite-holiday" data-time-format="2006-01-02">
</form>
{{end}}

Muxt should generate and add it to template_routes.go

type UpdateProfile struct{
  FirstName       string    `name:"first-name"`
  FavoriteHoliday time.time `name:"favorite-holiday"`
}

Support input types

input type Go type first draft Go type someday
checkbox bool
color string color.Color
date string time.Time
datetime-local string time.Time: use data-time-format to parse the string
email string string
file multipart.File
hidden string use data-type
image
month string time.Time: use data-time-format to parse the string
number string use data-type; if step is an int, use int otherwise use float64
password string use data-type
radio string use data-type
range string use data-types; if step is an int, use int otherwise use float64
search string use data-type
tel string use data-type
text string use data-type
time string time.Time: use data-time-format to parse the string
url url.URL
week string use data-time-format and parse time.Time

Initially add validation logic for:

@crhntr crhntr added the enhancement New feature or request label Aug 24, 2024
@crhntr crhntr changed the title Generate Go types for form fields Generate form structs from HTML input elements Aug 30, 2024
@crhntr crhntr changed the title Generate form structs from HTML input elements Generate Go form structs from HTML input elements Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request html-to-go
Projects
None yet
Development

No branches or pull requests

1 participant