Archive for October, 2007

Fun with the DOM

Tuesday, October 16th, 2007

Everything was going smoothly with Firefox. I was using innerHTML and the new arguments that I shoved into the DOM were getting posted to the server, no problem. Then, I switched over to IE to test and discovered that the newly created arguments weren’t showing up. Figuring it was a problem with IE, I inspected the DOM (by inserting a “return false;” statement in the form validator function.

Sure enough, the newly-created arguments were not getting appended to the DOM and therefore not posted to the server. I tried shoving the new arguments into the DOM but wound up getting this message:

Node cannot be inserted at the specified point in the hierarchy

Here’s what I was trying to do (intentional space at beginning of input to prevent WordPress rendering as HTML):

	newCell = '< input name="my_new_input" id="my_new_input" type="text" value="94109"/ >';

	var row = document.getElementById('my_table').getElementsByTagName('tr').childNodes[2];

	row.childNodes[i].innerHTML = newCell;

Figuring that the string-based method of creating an element was getting me anywhere, I tried to dynamically create and append the node:

	cellContent = row.childNodes[i].innerHTML;

	var inputNode = document.createElement("input"); 

	inputNode.setAttribute('type', 'text');

	inputNode.setAttribute('id', 'my_new_input');
	inputNode.setAttribute('name', 'my_new_input');

	inputNode.setAttribute('value', cellContent);
	inputNode.setAttribute('class', row.childNodes[i].className);	

	row.childNodes[i].replaceChild(inputNode, row.childNodes[i].firstChild);

(If name isn’t being set properly for you, you may want to check out this explanation about unexpected name property/attribute behavior in IE.)

Getting viPlugin to work in Aptana

Monday, October 15th, 2007

I’ve been checking out Eclipse and Aptana recently and I’m very impressed. When I found the viPlugin for Eclipse and then had an instinct that it might work with Aptana (what with Aptana’s core being Eclipse,) I decided to give it a shot.

I looked around and saw a tip on getting viPlugin to work with RadRails. Only thing is, I’m doing Javascript development on Windows XP and not using Rails. I finally came across Aptana HTML Editor and ViPlugin in Eclipse 3.2 and decided to give it a try. On the surface, the thread’s advice is straightforward. If you’re not familiar with extracting files and rebuilding JAR files, it might not make sense.

I went through the steps and edited the plugin.xml file. When I dropped the JAR back into the plugins folder and tried to open Aptana, I got this:

Unable to read workbench state. Workbench UI layout will be reset.

… and then Aptana wouldn’t even start. Ugh. I finally got it to work again by removing and reinstalling via the MSI (thereby losing the viPlugin so I needed to extract that again too.)

Since that didn’t work, I tried messing with the file associations (under Windows > Preferences > General > Editors > File Associations.) Then, I started getting this message:

Error loading lexer file

…telling me that I had a problem with the init for com.aptana.ide.editor.text.GenericTextEditor. Ugh. What to do? I tried a couple of things to fix the problem…

  1. Changing the default association for a text editor ( Windows > Preferences > Editors > File Associations )
  2. Reinstalling Aptana (making sure that the viPlugin JARs were not in the Aptana IDE Beta\plugins folder
  3. Refreshing the configuration( Help > Aptana Troubleshooting > Clean Configuration )

…with no success. I couldn’t find much help out there except for this. Then, I thought, maybe it’s a problem with Windows characters in my rebuild of the JAR file under XP. I gave it a try on a RHEL 5 box and it worked seemlessly. Ah. The feeling of accomplishment.

If you decide to get viPlugin for Aptana working, here are some things you should get before before diving in:

  1. a viPlugin license (order one here.)
  2. Knowledge of how to extract and rebuild JAR files
  3. a non-Windows system

If you’re really bent on having it work on Windows, you may follow the above thread: “Aptana HTML Editor and ViPlugin in Eclipse 3.2.”