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

htmxify #2

Open
gedw99 opened this issue Jan 19, 2024 · 2 comments
Open

htmxify #2

gedw99 opened this issue Jan 19, 2024 · 2 comments

Comments

@gedw99
Copy link

gedw99 commented Jan 19, 2024

with https://github.com/donseba/go-htmx

@donseba
Copy link
Owner

donseba commented Jan 23, 2024

you actually can without any change 😄 .

short example it your template you would do something like this :

myform.gohtml

<form class="space-y-6" hx-put="/config" hx-target=".element-form-container" hx-ext="json-enc-nested,notify">
    {{ form_render .Data.Form .Data.Errors "Loc" .Loc }}
    <div class="flex items-center justify-between">
        <button type="submit" class="inline-flex items-center rounded-md bg-orange-500 dark:bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-orange-700 ">Update Form</button>
    </div>
</form>

as you can see here, we can put all the hx attributes on the form element.

on the receiving end, in this case the put:config route we can validate and either respond with an hx-redirect or return the form/template with or without the errors.

I'm a bit in doubt on where to place the full example as i don't want to create dependances between the two packages.

@gedw99
Copy link
Author

gedw99 commented Feb 5, 2024

hey @donseba

you actually can without any change 😄 .

short example it your template you would do something like this :

myform.gohtml

<form class="space-y-6" hx-put="/config" hx-target=".element-form-container" hx-ext="json-enc-nested,notify">
    {{ form_render .Data.Form .Data.Errors "Loc" .Loc }}
    <div class="flex items-center justify-between">
        <button type="submit" class="inline-flex items-center rounded-md bg-orange-500 dark:bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-orange-700 ">Update Form</button>
    </div>
</form>

as you can see here, we can put all the hx attributes on the form element.

on the receiving end, in this case the put:config route we can validate and either respond with an hx-redirect or return the form/template with or without the errors.

I'm a bit in doubt on where to place the full example as i don't want to create dependances between the two packages.

I see what you mean.
So how about we make a repo called "demo", that has a go.work for each sub repo then ? Then there is no coupling and we have a place to build up demos where we are still enforcing this decoupling.

I actually use this pattern all the time. Here is what a Makefile looks like that wants a repo and to ensure it's an "island". go.work is a god send....

        git clone https://github.com/donseba/go-form
	@echo go-form >> .gitignore
	touch go.work
	go work use ./go-form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants