Tuesday, July 21, 2009

MooTools plugin - Remove all underlying text nodes of an element

Element.implement({
// Removes all underlying text nodes
removeTextNodes: function( startNode ){
var initialNode = this || startNode;
var childList = initialNode.childNodes;
if( childList.length === 0 ){ return; }

// Walk through all childNodes. If text - remove, else search/destroy
// potentially underlying text nodes
var currentNode;
var nodesToRemove = [];
for( var i = 0, len = childList.length; i < len; i++ ){
currentNode = childList[i];
if( currentNode.nodeName === '#text' ){ nodesToRemove.push( currentNode ); }
else { Element.removeTextNodes( currentNode ); }
}

// When all text nodes on the current level are found, remove them from the DOM
for( i = 0, len = nodesToRemove.length; i < len ; i++ ){
currentNode = nodesToRemove[i];
currentNode.parentNode.removeChild( currentNode );
}

return this;
}
});


I use this to clear/update a label that only contains a field and text. E.g.
<label id="label-with-field"><input type="radio">Some text<label>
$('label-with-field').removeTextNodes().appendText('newLabel')

The last line in the method, "return this;" makes the method chainable.

Friday, July 3, 2009

Accessible Web Forms With Domino - Addendum

I'm finally trying out what Jake probably have done for close to four years. Getting rid of "Use JavaScript when generating pages".

My addendum, is the choice of the submit element. In his article he chose <input type="submit" />. The downside with this is that the value attribute is used as a label for the button. I'm going to use <button type="submit">, which frees me to put whatever I want as a label. It makes it a lot easier to make internationalized button, as it lets you separate data from design.

E.g. (brackets indicates field)
<button type="submit" name="action" value="save">[cfd_save_label]</button>
<button type="submit" name="action" value="archive">[cfd_archive_label]</button>
<button type="submit" name="action" value="delete">[cfd_delete_label]</button>

He's probably using this already, but since I couldn't find a mention of it on his site, I thought I should share it with you.

If you're having trouble designing buttons across browsers, check out this guide.

Wednesday, July 1, 2009

HttpRequest class - Support for multivalue requests (e.g. checkbox)

A colleague of mine needed to process values from a form with checkboxes. In some instances, the amount of checked boxes (select all) was so great that he hit the 32k limit of Domino fields.

I suggested that he tried posting to an agent/used my HttpRequest class. This didn't work, as each checkboxvalue is sendt as a single parameter.

E.g. ...make_report?OpenAgent&user=tom&user=jane&user=jack

The previous version of the class only fetched the last parameter.
Dim request As New HttpRequest()
Print request.parameter("user")
' Prints jack


I updated the code, so that the class aggregates the values into a comma separated string dynamic array. Single value parameters are still Strings.
Dim request As New HttpRequest()
Print Join( request.parameter("user"), "," )
' Prints tom,jane,jack


>> The class in a txt-file

Share and enjoy!