Question about Surge and whether it's actually best practices?

I’m following along with the Surge screencast, and I’m at “Setting up the form”. As I understand it, the author is sending data to the backend every time anyone types in the registration form. Isn’t that inefficient?

Is this a great way to set up a registration form, or just a very basic and non-production ready example?

I’m just wondering. Thanks anyone for answering.

Yes. I have found the only reason to not use model.lazy is you are wanting live validation or doing a live search. model.lazy only sends the request on blur.

No idea about the screen cast, but I’m assuming it’s some sort of tutorial to show what you can do, so I’d go with the latter.

You can also cut all the requests and use something like
<form wire:submit.prevent="submit(Object.fromEntries(new FormData($">
I think I saw there was plans to make that formdata object easier and cleaner to use in livewire at some point in the future.

1 Like

Thanks for the reply! Food for thought. I’ll be making an old school registration form for now, I don’t need all those added requests.

Let’s hope there will be more examples of how Livewire can be efficient. I hope the “official” screencast by Livewire’s author will show me some great examples in the future!

Yeah, it’s just another tool for your toolbox. At the end of the day, does it help you accomplish what you were aiming for easier or not?

For a registration form, I could see it being useful if you wanted to be able to check if something like the user name is taken already. Some sites you will see they will make an ajax request on that field so you don’t have to submit the whole form to find out. Aside from that, I would agree with you that it’s just not needed because you can live validate just about everything else in javascript for the ux side of things, and your severside validation for the security part.

ETA: Even for that case, I would probably only livewire that one input box, and not the whole registration form.

If you don’t need it to be ‘live’ just post to the server as usual.