02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

350<br />

CHAPTER 10 ■ EXTENDING JQUERY<br />

});<br />

// If creating/editing an event, checks for valid dates<br />

if ( $(this).siblings("[name=action]").val()=="event_edit" )<br />

{<br />

if ( !$.validDate(start) || !$.validDate(end) )<br />

{<br />

alert("Valid dates only! (YYYY-MM-DD HH:MM:SS)");<br />

return false;<br />

}<br />

}<br />

// Sends the data to the processing file<br />

$.ajax({<br />

type: "POST",<br />

url: processFile,<br />

data: formData,<br />

success: function(data) {<br />

// If this is a deleted event, removes<br />

// it from the markup<br />

if ( remove===true )<br />

{<br />

fx.removeevent();<br />

}<br />

// Fades out the modal window<br />

fx.boxout();<br />

// If this is a new event, adds it to<br />

// the calendar<br />

if ( $("[name=event_id]").val().length==0<br />

&& remove===false )<br />

{<br />

fx.addevent(data, formData);<br />

}<br />

},<br />

error: function(msg) {<br />

alert(msg);<br />

}<br />

});<br />

$(".edit-form a:contains(cancel)")<br />

.live("click", function(event){...});<br />

});<br />

After saving the preceding code, you can reload http://localhost/ <strong>and</strong> try to submit a new event<br />

with bad date values. The result is identical to the result obtained when using the original validDate()<br />

function.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!