How to reload current page without losing any form data

The best way to keep form values after reloading the page is using Sysyphus.js javascript library.

It is easy to use:

First include the library in your pages:
<script src="js/sisyphus.min.js">

Then you need to call yourform.sisyphus(); function Suppose we have a form with id=”my-form”, here is an example showing how to use the library to keep form values:

<script src="js/sisyphus.min.js"></script>

<form action="" id="my-form" method="get">
  <input id="my-form-name-field" name="name" type="text" value="">
</form>

<script>
// Here we'll persist the form's data into localStorage on 
// every keystroke 
$( function() { 
  $( "#my-form" ).sisyphus(); 
  // or you can persist all forms data at one command 
  // $( "form" ).sisyphus(); 
 });
</script>

Note: to use it in drupal you have to include the library in hook_init() and use it inside your module or to include it and use it in your theme

How to install Eclipse JavaScript Development Tools (JSDT)

JSDP provide plug-ins that implement an IDE supporting the development of JavaScript applications and JavaScript within web applications. It adds a JavaScript project type and perspective to the Eclipse Workbench as well as a number of views, editors, wizards, and builders.

The most important thing for me is the code completion

To install JSDT in Eclipse:
go to Help>>Install new software

Continue reading

Adding Javascript to Drupal 7 Module

If you want to add javascript to your module you can do that several ways.

Starts with adding the following line to your MYMODULE .info file

scripts[] = MYMODULE.js

Where you can choose any name for your .js file

The next step is to create the MYMODULE.js file. The general template of the javascript file looks like:

(function ($) {
  Drupal.behaviors.MYMODULE = {
    attach: function (context, settings) {
      // Your Javascript code goes here

    }
  };
}(jQuery));

Continue reading