This is a migrated thread and some comments may be shown as answers.

Custom code plus submit form

3 Answers 1111 Views
Button
This is a migrated thread and some comments may be shown as answers.
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
Dean asked on 25 Mar 2021, 06:16 PM

Hi. I have a form that posts to a payment platform. I'd like to have a button that submits the form but also runs some other code, e.g. set a property to hide elements on the page.

 

Can I do this?   If so should I use ButtonType="ButtonType.Submit" plus an OnClick?  This doesn't seem to work.  Or should I use a ButtonType.Button and use some code to post the form?  (If so how could I do that)?

 

Thanks.

Dean

3 Answers, 1 is accepted

Sort by
0
Stamo Gochev
Telerik team
answered on 30 Mar 2021, 08:28 AM

Hello,

If you are using the standard blazor form then you can use the "OnSubmit" event as explained in the docs to run some code when the form is actually submitted. On the other hand, the same can be achieved with TelerikForm component and its "OnSubmit" event if you are using it instead.

A similar scenario can be handled by using the "OnClick" event handler of the button if you do not need to depend on the functionality of the form. As this is expected to work, can you send me a runnable example, which demonstrates the issue you are facing, so I can inspect it?

Regards,
Stamo Gochev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 30 Mar 2021, 09:46 AM
Apologies, I should have been clearer.  This is a standard HTML form, and AFAIK it has to be, because it posts to an external URL (a payment gateway).  I assume I can't use a Blazor form or Telerik form for that purpose?  So I am stuck with an HTML form, but want some way to run code as it submits (just to hide the submit button).  Is this possible with a TelerikButton?
0
Stamo Gochev
Telerik team
answered on 02 Apr 2021, 05:05 AM

Hi,

The blazor form and TelerikForm components do not post to a concrete remote URL by default, but it is still possible to use their event handlers to make an API call to a remote endpoint.

Using a standard <form> HTML element does not provide any integration with the blazor framework out of the box, so things like validation will not be handled. In this scenario, it is not that important if TelerikButton with ButtonType="Submit" is used or not as it will behave as the standard <button> HTML element (including its @onclick event). One more option you can try is using the native "submit" event of the form to execute additional logic (<form @onsubmit="..."></form>).

Regards,
Stamo Gochev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Button
Asked by
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Stamo Gochev
Telerik team
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
Share this question
or