Welcome Guest, Not a member yet? Register   Sign In
ci and simplemodal
#1

[eluser]otn3m3m[/eluser]
I am using simplemodal dialog. The main view commits ajax post to the controller to recieve the text for the dialog.

Problem is when i press the submit button in the dialog, for some reason it submits the form twice. I know this because the page does two alerts ("Event text").

Why is it submitting twice and how can i fix it?

thanks,


main view

Code:
<html>
<head>
<!-- jquery and simplemodal scripts --!>
</head>

<body>
<a href='#'>New</a>

script

function new_project(){

    $.post('http://localhost:8080/pm/index.php/project/get_dg_new_project', {}, function callback(response) {
            $(response).modal();
    });
}

script
&lt;/body&gt;
&lt;/html&gt;

Dialog view

Code:
<div id='basic-modal'><h2>Basic Modal Dialog</h2>

<h1>SimpleModal</h1>

&lt;form id="target" action="destination.html"&gt;
  &lt;input type="text" value="Hello there" /&gt;
  &lt;input type="submit" value="Go" /&gt;
&lt;/form&gt;

script
    $('#target').submit(function() {
      alert('Event text');
      return false;
    });
script

</div>
#2

[eluser]Unknown[/eluser]
Instead of putting the submit code in the response, try putting it in the SimpleModal onShow callback.

Code:
$(response).modal({
  onShow: function (dialog) {
    $('form', dialog.data[0]).submit((function () {
      alert('here');
      return false;
    )
  }
});
#3

[eluser]otn3m3m[/eluser]
solved the problem. For some reason the double alerts only occur if i use
jquery-1.4.2.min.js

If i use jquery v1.3.2 it works as expected.




Theme © iAndrew 2016 - Forum software by © MyBB