CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Default Button in Forms and Dialogs

Share your useful code here.

by kattunga » 02 Oct 2013 20:31

To set a default button to be clicked when the "Enter" key is pressed in any "input" component, we need to do:

In modal dialogs

Suppose you have a dialog named "Dialog" with a button "BtnLogin" which we want to be the default button.

Set Dialog.JQDialogOptions.OnOpen.Script, preferentially using the design-time editor with the following code.

Code: Select all
$(document).ready(function () {
    $("input").on("keydown", function (event) {
        var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
        if (keycode == 13) {
            $(<#BtnLogin#>).click();
            return false;
        } else {
            return true;
        }
    });
});


In standard TIWAppForm:

Suppose you have a form named "FLogin" with a button "BtnLogin" which we want to be the default button.

In property FLogin.JavaScript add the above code.

In event FLogin.OnRender add:

Code: Select all
procedure TFLogin.IWAppFormRender(Sender: TObject);
begin
  JavaScript.Text := StringReplace(JavaScript.Text,'$(<#btnLogin#>)','document.getElementById('''+BtnLogin.JQHTMLName+''')',[rfReplaceAll,rfIgnoreCase]);
end;
kattunga
 
Posts: 83
Joined: 01 Oct 2013 19:03

by Jorge Sousa » 02 Oct 2013 23:35

Thank you very much Christian
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58


Return to Community Code

cron

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.