Phillip Haydon

It works on my PC.

jQuery Serialize a Fieldset (Update)

clock January 23, 2010 04:40 by author Phillip

Towards the end of last year Bart pointed out the Chrome and Firefox don’t actually copy the values when using .clone()

http://www.philliphaydon.com/post/2009/07/11/jQuery-Serialize-a-Fieldset.aspx#comment

What it seems like is happening, is browsers such as Safari, Opera, and Internet Explorer, will copy the latest version of the element when using .cloneNode from the DOM.

However Firefox and Chrome only copy the original version. This means they copy the element before we populated it with data.

For jQuery 1.3.2 I suggested to Bart as a fix, to loop the elements and re-assign the values.

<script type="text/javascript">
   1:  
   2:   function Serialize(fieldsetName) { 
   3:     $('body').append('<form id="form-to-submit" style="visibility:hidden;"></form>'); 
   4:     $('#form-to-submit').html($(fieldsetName).clone()); 
   5:  
   6:     $(fieldsetName).find('select,textarea,input').each(function(i, e) 
   7:     { 
   8:       $('#form-to-submit').find('select,textarea,input').eq(i).val($(e).val()); 
   9:     }); 
  10:  
  11:     var data = $('#form-to-submit').serialize(); 
  12:     $('#form-to-submit').remove(); 
  13:     alert(data); 
  14:     return data; 
  15:   } 
</script>

It’s a bit of a hack, but it works.

However on the 14th of January, jQuery 1.4 was released, and reading the notes on http://jquery14.com/day-01/jquery-14 there's an exciting little snippet towards the bottom.

At the bottom is a section I care about a lot. It’s called “Backwards-Incompatible Changes” or changes from the previous version that could break your site if you were to just rush in to upgrade.

The 2nd item on there is:

.clone(true) now copies events AND data instead of just events.

Is that awesome or WHAT! No more having to to write work-around’s, which I was getting worried about since all the bugs logged against the clone issue were were all set to “wont be fixed”

Anyone who hasn’t read that note list should give it a skim, lots of changes and performance updates to jQuery.



LightSpeed 3.0 released!

clock December 16, 2009 04:50 by author Phillip

Woooo I'm late to the game, after forgetting to add MindScapes RSS to Google Reader after I left Datacom, I missed the release of LightSpeed 3.0 on Monday.

http://www.mindscape.co.nz/blog/index.php/2009/12/14/lightspeed-3-0-released/

Time to go test out the new querying and joins support. The plan is to use LS3 on ITCompiler.



I hate Adobe...

clock December 2, 2009 08:53 by author Phillip

Every now-n-then your bound to come across a piece of WTF functionality in a program, and you can't figure out why on earth a developer would put it in or make it function the way it does.

I just found one of those WTF's in Adobe Photoshop.

I had a file I hadn't yet saved, and thought "you know what, I'll rename that layer", so I clicked the layer and pressed F2 thinking it would just rename similar to how it does in Explorer, or Visual Studio, or 100's of other programs.

Poof.

My work was gone, because apparently Adobe decided that rename wasn't a good function for the F2 key, it must be a "close the file im working on" key.

But wait, if you click "File" and look at the "Close Window" shortcut, it happens to be "CTRL + W", not F2, I couldn't even find how to unset the F2 key from "Keyboard Shortcuts" because it's not assigned to anything...

<-- not happy.



YouTube’s forced advertising…

clock November 21, 2009 08:32 by author Phillip

Visited YouTube this morning and was presented with a massive advertisement for Assassins’s Creed II. Not caring much for it and wanting screen real estate space back i opted to click the “Close Ad” button in the top right hand corner.

image

Only, it didn’t close the advert, it clicked on the actual banner. Why?

The advert isn’t actually part of YouTube, it’s from doubleclick.com

Apparently doubleclick.com fails at detecting browsers and decided that Opera should be served up a full on jpg of the advert.

PID_1186775_back[1]

Opening YouTube in IE8 however i was presented with a full on flash banner, and when i clicked Close Ad, you wouldn’t believe what happened… The advert closed!

I wish more developers would recognize that there other browsers besides IE, Firefox and Safari, such as Chrome and Opera, and start developing for them. It’s not difficult considering Opera is probably, if not is the most standards compliant browser available. At least, unlike Failfox, it doesn’t create it’s own standards, or like IE, fail to implement standards to begin with.

DoubleClick Fail!



Microsoft’s Answer to a CMS?

clock November 11, 2009 21:03 by author Phillip

Well not “Microsoft” but the developers from the ASP.Net team have today released Orchard. A free open source CMS for the ASP.Net Platform.

I heard about this a while ago and have been very excited, it’s about time there was a good free CMS for .net, but what worries me is the codeplex homepage for Orchard says the developers of Oxite are involved, and I personally cannot stand Oxite…

However the roadmap for the CMS looks pretty impressive, I can’t wait till they add Blogging support so I can migrate my blog over.

Actually… “Blog – Implement Oxite functionality as an Orchard module” in the feature list is disheartening… Hopefully Oxites blogging functionality will work better in Orchard. *fingers crossed*

Time to fire up AnkhSVN and grab me a copy of the source code!



jQuery Serialize a Fieldset Part 2: Fixing ClientID’s

clock November 10, 2009 16:05 by author Phillip

A while ago I wrote a post on using jQuery Serialize against a fieldset(s) for the use on ASP.Net Web Forms. Since Web Forms only have one form, us ASP.Net Developers miss out on all the joy of the jQuery Functionality. (the post has generated a lot of traffic to my blog too.)

Something I have been meaning to add to that post however, is what we do after we have grabbed all the fieldset field elements. One problem is INamingContainer ID’s on all the fields, the second thing, is making an AJAX request.

When making AJAX requests on website’s I personally don’t like the idea of calling a Web Service or WCF Service from JavaScript, or using those old Page Method things (not even sure people still use those).

Neatest way I’ve found, which I’ve been using for about 5 years now, is HTTPHandlers.

In this post I’m gonna show how to fix up the ClientID’s, and later I’ll post about using HTTPHandlers.

Removing ClientID’s

Using the same project I posted last time, I’ve taken the fieldsets and moved them into their own User Control, and changed the form elements to ASP.Net Server Controls. This results in HTML rendered like:

<fieldset class="fsLoginForm">
<legend>Login Fieldset</legend>
<ul>
<li>Email: <input name="ccTestForm$txtEmail" type="text" id="ccTestForm_txtEmail" /></li>
<li>Password: <input name="ccTestForm$txtPassword" type="text" id="ccTestForm_txtPassword" /></li>
</ul>
</fieldset>

When I run the page to see the serialized data we get:

image

Yucky yucky form names. Makes it impossible to use this data for anything, anywhere we post it, we wont be able to get the data without knowing the INamingContainer its sitting in, and even if you did know, it can’t be reused, if you put the form on another page the names could be completely different.

Good thing is, once we clone the fieldsets to serialize them, we can rename all those field names relatively easily.

//Clone the fieldset into the new form.
$('#form-to-submit').html($(fieldsetName).clone());

//Rename all the field 'name' attributes
$('#form-to-submit').find('input, select, textarea').each(function(i, e)
{
var newName = $(e).attr('name').substring($(e).attr('name').lastIndexOf('$') + 1);
$(e).attr('name', newName);
});


//Serialize the data
var data = $('#form-to-submit').serialize();

I’ve used the same function from the previous post, just included a loop after the clone, before the serialize, basically it loops through each form element, finds the last part of the name, and reassigns it back to the element.

Running the same piece of code again produces:

image

Now we have nice clean names to post somewhere.

Thats all for now.



Moving VisualSVN to a New Server with a New Repository Address

clock October 20, 2009 15:51 by author Phillip

I recently moved my served from Crystal Tech to MDWebHosting. (don’t get me wrong, Crystal Tech is one of the best hosting providers I’ve ever had, just getting expensive converting USD to AUD so I figured it’s time to get a server a little closer to home.

Moving VisualSVN was a piece of cake, just installed VisualSVN on the new server, zipped up the repository directory, and dropped it over the top of the new one, the only downside was the old server used port 1337. (original I know…)

The problem was the new server at MDWebHosting blocked the port, and didn’t really want to open it just for one person, they supplied me with a list of all open ports and I decided to just use one of those.

What I wanted to avoid was having to create a new working version on my computer, and Google wasn’t doing much for me. I figured that the repository location was just going to be in one of the SVN files, and I was right. Opening up the “entries” file provided the URL within the first few lines:

image

I changed “1337” to “8080” and that worked fine, what I didn’t realise was that I had 407 other files to update as well…

image

I opened all 407 files into EditPlus and updated on all open files, saved it, and opened my project back up, updated and committed and everything worked perfect!

So all my revisions are intact and I didn’t have to rebuild the repository or anything.

<3 SVN



Scott Guthrie <3

clock October 9, 2009 11:06 by author Phillip

Recently Scott Gurhrie posted Announcing the WebsiteSpark Program, which by the way is an awesome offering!

After reading the article I found out about BizSpark, another program offering for startups, which I thought would be great for the startup I'm doing with a couple of friends, although it's targeted towards non-web related stuff (but not excluding).

BizSpark fits into what we would be doing, so I applied for it.

I applied on September 27th, and received a pretty vague email...

 

The email says it takes up to 3 days to process, but after a week I got impatient... I had heard nothing, and while reading forums heard that a couple of other people were declined without reason.

So I began emailing, I tried emailing Microsoft Support as directed in the email, who told me to email MSDN Subscriptions, who told me to email "MS Champs team" (what ever that is...).

I tried emailing startups. (the emails from the "team" on the biz spark website).

Nothing...

So I decided to email Scott. He did say to in his article.

If you have any problems enrolling, you can also send me mail (scottgu@microsoft.com) and I can connect you with someone who can help.

So I did, and wow. I got an auto response saying to expect long delays since he's sick.

Within 3 minutes of emailing him, yes 3 minutes! He had forwarded my email onto someone, and while out at lunch I got a response from Julien.

Julien explained to me what the issue was, which was that we looked like a Digital Agency / Design shop. I replied explaining what we were doing and a couple of projects we are working on, and within minutes he replied letting me know I was approved.

Now I'm a happy Biz Spark member all thanks to Scott and Julien!

Scott definitely is a great representative for Microsoft, makes me appreciate using Microsoft products and technologies.



Microshaft on Bing

clock September 17, 2009 06:23 by author Phillip

Doing random searchs in www.bing-vs-google.com i thought I would amuse myself and type Microshaft... The result was kinda funny...

Bing has indexed Microsoft support site as Microshaft.

Fun times.



Visual Studio 2008, SVN, and different connection strings with different users…

clock August 30, 2009 06:39 by author Phillip

I’m working on a project called ProjectAwesome. (obvious it’s the code name, and it’s an awesome one at that!) This is a project I’m working on with a friend, so we work from home.

My dedicated server runs VisualSVN Server. And both of us have Ankh SVN installed on Visual Studio 2008. The problem we both have is our development environments are not identical. We both use a different operating system, and we both use a different database version.

My friend is using Windows Server 2008, and SQL Server 2005. While I’m using Windows Vista, and just recently Windows 7 (which by the way kicks ass!), and SQL Server 2008.

The most annoying commit we do to each other is the Connection String. I change mine to use .\SQL2008, he changes his to .\SQL2005, we both curse at each other…

So what I've done is exclude it by default from being committed. The way I’ve done this is I extracted it to it’s own configuration file. I had done this for all the other sections.

image

 

This makes the web.config file nice and tidy too :)

  1.   <appSettings configSource="_configuration\webAppSettings.config" />
  2.   <connectionStrings configSource="_configuration\connectionStrings.config" />
  3.   <urlrewritingnet configSource="_configuration\urlRewriting.config" />

 

The next thing to do was exclude the change from SVN. Basically all I had to do was go into the SVN properties for the file, this I did by opening up the pending changes window. (File > Subversion > Pending Changes)

image 

Right click the file and select properties, which gives me an option “Change List”, I set this to “ignore-on-commit”.

image

And that's it. Now both of us can makes changes to the connection strings, commit our changes and never have conflicts and arguments over who checked in the web.config.

The best thing about splitting it out is if we do make web.config changes, they can be committed without breaking the connection strings :)