20 Feb 2009 @ 12:19 PM 

I came across this picture recently and thought it was worth a posting.

Pale Blue Dot

Tags Categories: Uncategorized Posted By: admin
Last Edit: 20 Feb 2009 @ 12 19 PM

E-mailPermalinkComments (0)
 12 Feb 2009 @ 11:31 AM 

I had a problem recently with Jquery where I wanted to clone a form. I had a model pop-up box which contained a large form. The user could click a button to bring the form up, enter the details and then hit ok to close the form again. They could also go back at any timeĀ  and change the details they had entered in the form. My idea was to provide a cancel button so that if the user decided that they wanted to discard the changes they could hit this button and it would roll-back the form fields to their previous values.

This sounded like a prime candidate for the Clone function that Jquery provides. I could clone the form and if the user hit cancel I could just replace the current form with the cloned one and et voila the original values would be stored. Except that _DISASTER_ for some reason Jquery’s clone method doesn’t clone the select values.

There are 2 arguments for what should be done when you clone a form. One side argues that you should copy the elements in their ‘raw’ default state and the other side says you should copy the form, values and all. In an ideal world there should probably be a flag to select either but the current Jquery approach appear to be consistent, textfield values are copied over but the selects appear to be the only input type that doesn’t. (I’ll do a check later and test every input type to make sure).

Now this functionality was pretty fundamental to what I was doing so I spent a fair bit of time banging my head off the wall in frustration at this point. Later that night though I figured out that it would be really easy to fix such is the awesome power of Jquery and it’s so obvious that I don’t know what I was getting so het up about. But, to save anyone else from pulling their hair out – you can use this function to clone a form including the select values.

[sourcecode ]

function cloneForm(id, withEvents)
{
var clone = $(’#'+id).clone(withEvents);
var selvals = [];
$(’#'+id+” select”).each(function()
{
selvals.push($(this).val());
});
clone.find(”select”).each(

function()
{
$(this).val(selvals.shift());
});
return clone;
}

[/sourcecode]

The second argument to this function is a boolean that allows you to specify if you want the clone to retain any events that are attached.

Tags Categories: Uncategorized Posted By: admin
Last Edit: 16 Mar 2009 @ 02 28 PM

E-mailPermalinkComments (3)
\/ More Options ...
  • No categories
Change Theme...
  • Role »
  • Posts »
  • Comments »
Change Theme...
  • VoidVoid (Default)
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LiteLightweight