javascript - jQuery UI dialog closes on enter in input field -


i open dialog button place cursor in input field , presses enter dialog closes , line inserted address bar:

address bar

jquery:

$('#dialog').load("form-incident.php").dialog({     title: "add incident",     autoopen: false,     resizable: false,     width: 800,     modal:true,     position: ['center', 'top+50'],     buttons: {         add: function(){              $.ajax({                 url     : 'save.php',                 type    : 'post',                 data    : $('form').serialize(),                 context: $(this),                 success: function (result) {                     if (result === "true") {                         alert('incident has been added successfully');                     } else {                         alert('error: cannot insert data mysql table');                     }                     window.location.reload();                     $(this).dialog( "close" );                 },                 error   : function(){                     alert('error: check database connection');                 }             });         },         cancel: function() {             $(this).dialog( "close" );         }     } }); 

form-incident.php:

<form>     name: <input type="text" name="name" id="name"><br><br>     project:     <select name="project" id="project">         <option value="test">test</option>     </select><br><br>     incident:<br> <textarea name="incident" id="incident" style="resize:none; width: 100%;" rows="14" cols="94"></textarea> </form> 

how can fix problem dialog box not close still reacts enter if there suggestions earlier form filled out?

okay, forgot implicit submission still happen if there single input element in form, if there isn't submit button.

so, looks problem happening form being submitted. in case, calling preventdefault() on submit fix it.

i threw fiddle code snippets above, , able reproduce problem. once put in preventdefault(), stopped happening. please check out, , see how differs live code.

https://jsfiddle.net/elezar/u0sfx22p/2/


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -