Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I stop EditForm submitting when updating a List item?

I have a form where I ca add and remove products, almost like a basket. But when I add/remove a product from the list, the form submits.

Is there a way to prevent this from happening?

<EditForm EditContext="FormEditContext" method="post" OnValidSubmit="SubmitForm">
<MatSelectItem 
    Context="Product"
    @bind-Value="@formModel.Product"
    TValue="TariffProductQuoteViewModel"
    Items="AvailableProducts.ToList()"
    Disabled="!CanEdit">
     <ItemTemplate>
        @Product.ProductName
     </ItemTemplate>
</MatSelectItem>
    <MatButton OnClick="AddProduct">+ Add Product</MatButton>
</EditForm>
public void AddProduct()
{
    formModel.Items.Add(new Product()
    {
        ProductId = AvailableProducts.FirstOrDefault().Id,
        Product = AvailableProducts.FirstOrDefault(),
        Quantity = 1,
    });
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have to set the Type to button on MatButton, because default value is submit (which is also true for html button).

 <MatButton OnClick="AddProduct" Type="button">+ Add Product</MatButton>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading