(Solved) UI page - Stop UI_form submitting when user press enter in input field

Sitrix
Tera Guru

Hello good people 🙂

 

Sorry for the basic question, but I've searched around with no luck. The title pretty much says it all, is there a way to avoid this functionality?

Even a simple <input> seems to submit the form, should the user type something and finish with enter.

 

Example:

 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:ui_form>
		<input></input>
	<g:dialog_button_ok type="submit"/>
	</g:ui_form>
</j:jelly>

 

 

 

The issue, is that users are likely to submit an unfinished form by mistake. Some fields are optional, but they shouldn't submit a half filled form by accident.

 

Changing the "dialog_button_ok" button to type="button" avoids this, but I've yet to be able to submit the form from client script; thought it would be possible using a "document.getElementById" and then doing a .submit() - but it doesn't seem to work.

 

Help would be much appreciated 🙂

 

 

1 ACCEPTED SOLUTION

Sitrix
Tera Guru

For anyone interested, its solvable by checking for keydown event. Add this to client script.

 

$j(document).ready(function () {
    $j(window).keydown(function (event) {
        if (event.keyCode == 13 && !$j(event.target).is(":button")) {
            event.preventDefault();
            return false;
        }
    });
});

 

View solution in original post

1 REPLY 1

Sitrix
Tera Guru

For anyone interested, its solvable by checking for keydown event. Add this to client script.

 

$j(document).ready(function () {
    $j(window).keydown(function (event) {
        if (event.keyCode == 13 && !$j(event.target).is(":button")) {
            event.preventDefault();
            return false;
        }
    });
});