Click To Edit

The click to edit pattern provides a way to offer inline editing of all or part of a record without a page refresh.

return Div(
	hx.Target(htmx.TargetThis),
	hx.Swap(swap.OuterHTML),
	Dl(
		Dt(g.Text("First Name")),
		Dd(g.Text(form.FirstName)),
		Dt(g.Text("Last Name")),
		Dd(g.Text(form.LastName)),
		Dt(g.Text("Email")),
		Dd(g.Text(form.Email)),
		Div(Role("group"),
			Button(
				hx.Get("/examples/gomponents/click-to-edit/edit/"),
				g.Text("Click to edit"),
			),
		),
	),
)
return FormEl(
	Method("POST"),
	Action("/examples/gomponents/click-to-edit/edit/"),
	hx.Post("/examples/gomponents/click-to-edit/edit/"),
	hx.Target(htmx.TargetThis),
	hx.Swap(swap.OuterHTML),
	Label(
		g.Text("First Name"),
		Input(
			Type("text"),
			Name("firstName"),
			Value(form.FirstName),
			g.If(
				form.HasError("FirstName"),
				g.Attr("aria-invalid", "true"),
			),
		),
		g.If(
			form.HasError("FirstName"),
			Small(g.Text(form.GetError("FirstName"))),
		),
	),
	Label(
		g.Text("Last Name"),
		Input(
			Type("text"),
			Name("lastName"),
			Value(form.LastName),
			g.If(
				form.HasError("LastName"),
				g.Attr("aria-invalid", "true"),
			),
		),
		g.If(
			form.HasError("LastName"),
			Small(g.Text(form.GetError("LastName"))),
		),
	),
	Label(
		g.Text("Email"),
		Input(
			Type("text"),
			Name("email"),
			Value(form.Email),
			g.If(
				form.HasError("Email"),
				g.Attr("aria-invalid", "true"),
			),
		),
		g.If(
			form.HasError("Email"),
			Small(g.Text(form.GetError("Email"))),
		),
	),
	Div(
		Role("group"),
		Button(
			Type("submit"),
			g.Text("Submit"),
		),
		A(
			Href("/examples/gomponents/click-to-edit/"),
			Role("button"),
			hx.Get("/examples/gomponents/click-to-edit/view/"),
			g.Text("Cancel"),
		),
	),
)

Source

Demo

First Name
None
Last Name
None
Email
None