Home ::
::  Blog
::  Photos
::  About
::  Contact

«« :: 2008 Nov :: »»


1 comments 2008 nov 20 (thu) 11:55  ::  Getting Dojo's dijit.Editor to work in a form

dijit.Editor is one of those so-close-yet-so-far things. It gives users a way to enter fancy formatted text without having to learn HTML, and is part of the Dojo Toolkit, which is supposed to make Javascript easier to work with. But it was a real PITA to get Editor working with what I think its most common use case: replacing a common <textarea> in a form. I ended up spending almost an entire day googling and paging through O'Reilly's excellent book on Dojo before I got it to work. Here's what I finally figured out.

The Problem:

dijit.Editor can be inserted into a <textarea> like you insert other dijit widgets, using dojoType="dijit.Editor". The editor displays fine and works perfectly, except that it doesn't actually save to your form for some reason.

The Solution:

You have to make your actual textarea a hidden field, use <div> tags for Editor instead of <textarea>, and include some code in the dojo.addOnLoad() function that copies the text of the dijit.Editor field into the hidden field when the form is submitted. There's a good writeup of this over at Dojo Campus.org.

Thoughts

This problem is not mentioned anywhere that I could find in the official Dojo docs. I can see Dojo partisans making the case that dijit.Editor is a Dijit Application rather than one of the Dijit forms widgets, and that this justifies the special handling required. However, I think replacing the plain ol` <textarea> is probably the most common use case for dijit.Editor, so there really should be better documentation of this.

This experience makes me wonder if Dojo is really the right tool for the job I'm doing. I think I might have another look at jQuery...

P.S. JavaScript: The Good Parts is another really helpful book if you're getting into the language.

 

1 comments on this post

Passerby at 11:36 a.m. on Fri 26 Aug 2011

Wow. That is awful.

You know, I know there are a lot of heavy hitters sponsoring the Dojo Framework, like (Sun/Oracle?), IBM, Cisco, AOL... But how could anyone blunder so ridiculously and ruin the codability of a WYSIWYG Editor like that. It really makes you wonder what their thinking when they build this crap.

I mean the natural conclusion ANYONE would draw from one's first instincts about HTML and basic adding WYSIWYG conventions like bold, italics, underlining, colors and size, is that you add it to a the existing textarea form element.

I know they probably have technical reasons for going the way they did. But man, making it overly complicated, essentially ruins any incetive to implement it.

There are a number of beefs I have with Dojo, and it's often issues like this, where the sever the ability for intuitive graceful degradation.

Yuck.

And, I absolutely agree with your sentiment about re-visiting JQuery. They have a decent widgeting library, and it's comparable to Dijit.

Add a comment