Check if a form has changes before unload the page

Html: <form data-js-dirtyform-check=”true”> <!– form inputs –> </form> Javascript: // dirty form check to avoid going back in history and lose data $(“[data-js-dirtyform-check]”).each(function () { var _isDirtyAndNotSubmit = false; $(this).find(“:input”).on(“change.js-dirtyform-check”, function () { _isDirtyAndNotSubmit = true; }); $(document).on(“submit.js-dirtyform-check”, function () { // on window submit, disable the dirt check _isDirtyAndNotSubmit Read more…

File upload by ajax with Laravel and jQuery

Some Controller method in Laravel 4.2, with some JSON responses: public function postUpload() { Input::file(‘uploadfile’)->move(storage_path(‘temp/’), ‘import.xls’); try { Artisan::call(‘importexcelfile’, [ ‘file’ => ‘app/storage/temp/import.xlsm’, ]); return Response::json([ ‘result’ => 1 ]); } catch (Exception $e) { return Response::json([ ‘result’ => -1, ‘message’ => $e->getMessage(), ]); } } Some jQuery code, which handles Read more…

notify user for unsaved changes

This script notifies the user before he leaves the page for unsaved changes. It fires at the page unload event and opens a special alert box. The user can now decide if he wants to proceed or cancel. var isDirty = false; $(“form :input, form textarea”).on(“change”, function(event){ isDirty = true; }); $(“form”).on(“submit”, function(event){ Read more…

creating an on page search with jQuery

The mission is to create an on page search with jQuery on a table of elements. The search only display rows with the given search term in it. All other rows are hidden. This is a quick prototype: The markup <input type=”text” id=”search” placeholder=”searchterm”> <table> <tbody> <tr> <td>searchterm</td> </tr> <tr> <td>searchterm</td> </tr> Read more…