Skip to main content

Posts

Showing posts from November, 2012

Your Server-Side Form Library

If it isn't already obvious from my previous posts, I've been spending a lot of time on the client side of things with JavaScript and the Dojo toolkit.
I had a chance last weekend to show off a little bit of Dojo and once I got past the lightweight technique for bootstrapping it from the server, my demonstration suddenly got a lot less glamorous.

I think part of it got lost amidst what resembled gruelling swing form code.  I was lucky in that I already had some completed forms to show off, so it was possible to show the kind of experiences you can deliver when you use a good client-side framework.

There was however a takeaway for me which after a lot of thinking, I think I've managed to figure out...
It's Holding you Back! Your server side form library is killing your UX, coupling your model to the view and tying down your options client-side.

I've worked with forms in Symfony 1.4 extensively and have become quite adept at bending them to whatever need may arise.  …

Password Checking with Dojo

If you're puzzling over how to create the usual password and confirmation fields using Dojo,  try out this approach that I came up with for a project I'm working on:

var passwordCheck = new ValidationTextBox({ id: "password-check", placeholder: "Password again...", type: "password", intermediateChanges: true, invalidMessage: "The value you have entered does not match the password you have chosen..." });this.password = new ValidationTextBox({ name: "password", id: "password", placeholder: "Password...", type: "password", intermediateChanges: true, onChange: function () { passwordCheck.set("pattern", this.value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); if(passwordCheck.value) { passwordCheck.validate(); } } });
It's really simple and keeps everything lean, relying on as little implementation code as possible.  Simply put, every time the password …

Dojo and Rails CSRF

If you're using Dojo and Rails & are having some issues with asyncs to your server being rejected, consider employing the following in your xhr or JsonRest:

headers: { "X-CSRF-Token": query("meta[name='csrf-token']").attr("content") }
In my particular situation, I was trying to do HTTP POSTs and Rails was terminating my session likely because it perceived the lack of a CSRF token as a hijack attempt.  The code here simply adds the token as an HTTP header in the request.

I think once I've had some time with this fix, I might look at subclassing these objects for my project and pre-populating the header.  Then I'll simply substitute my implementations for the default Dojo ones.

Which - come to think of it - would probably make for a good case when discussing the advantages of AMD.

Fear not, if you happen to be using jQuery and are experiencing this issue, here's an equivalent solution.