X-editable(select): Avoid submitting on pressing enter key

1.7k views Asked by At

I need to avoid submitting an x-editable select by pressing enter key, and allow the user to only submit it by clicking the submit button.

I can't find any reference in the documentation about how to achieve this in the x-editable.

Here's x-editable initialization code:

$(".xe-user").editable({
            mode        : "popup",
            type        : "select",
            source      : webroot + "/index.php/user/getUser",
            name        : "Id_user",
            toogle      : "manual",
            url         : url
        }); 
2

There are 2 answers

2
Brandon Brown On BEST ANSWER

Do this

$('.data-item').on('shown', function(e, editable) {
    editable.input.$input.keypress(function (e) {
        if (e.which == 13) {
            return false;
        }
    });
});

Where '.data-item' is the editable element(s). You'll need to have your own "save" button to submit the form if you disable submitting via the enter button.

0
Md. Razu Haolader On

jQuery(document).on('keypress','.editable-text',function(e){
                if(e.which == 13) {
                        return false;
                }
        });

Here '.editable-text' is your input filed class.