hydrostack / hydro

Hydro brings stateful and reactive components to ASP.NET Core without writing JavaScript
https://usehydro.dev
MIT License
716 stars 17 forks source link

Forms not keeping data and refresh by itself #31

Closed MycroBeat closed 4 months ago

MycroBeat commented 5 months ago

Hello. Very interesting project. Keep up working on it.

I found a bug with forms on latest 0.14.0 release. On the latest release, when you click the submit button on a form, the page the data is lost and the page refresh by itself. I'm using the example with form validation from the documentation like in this example below. Even if i bind the input using hydro-bind the symtoms are the same.

public class FormValid : HydroComponent { [Required, MaxLength(50)] public string? Name { get; set; } public void Submit() { if (string.IsNullOrEmpty(Name) == true) { Console.WriteLine("Name is null"); } Console.WriteLine("A:" + Name); } }

@model FormValid <form hydro-on:submit="@(() => Model.Submit())"> <label asp-for="Name"></label> <input class="form-control" asp-for="Name" hydro-bind /> <span asp-validation-for="Name"></span> <button class="btn btn-outline-primary" type="submit">Submit</button> </form>

This example works ok in 0.11.0.

kjeske commented 5 months ago

Thank you for the report. The bug is now fixed.

MycroBeat commented 5 months ago

Look fixed, but i have some question. It is normal when first i submit, change the change and the resubmited and the text get the first submit? I attach a video. Maybe i'm using the hydro incorrectly. i checked the code and this my be a problem with latest bidding feature from hydro.js after January 2024.

https://github.com/hydrostack/hydro/assets/19955745/66bac3b6-07dc-47e1-9f78-1eaced28e33e

kjeske commented 5 months ago

Yes you're correct. It seems there was a bug introduced releted to the race condition between bind and action. That's why if you focus out the field first and then click submit it works. I will fix that shortly, thanks again.

kjeske commented 4 months ago

Moved to #35