Sat 15 May 2004 07:55:08 AM UTC, comment #2:
Well, I have a need for some rather esoteric dynamic elements, much of which stems from the fact I'm working on xhtml sites that need to comply to accessibility rules. In order to generate them, I need to get 'down and dirty' with the guts of GSWHTMLDynamicElement
One of these is a validated textfield. The use I propose is as follows:
I generate a form filled with validated textfields, each of which has, among other things, a binding to an error dictionary
When the form is submitted, the validating code (typically the action of the submit button) populates an error dictionary, keyed on the names of the bound values being validated, containing the error string for that particular textfield.
We go back around the event loop, where we hit appendToResponse:inContext:. In this, the textfields look in the error dictionary (which is bound, remember) for errors corresponding to themselves (where the key for 'themselves' is found by interrogating their own binding for 'value'). If they find one, they 'hilight' themselves (as I'm using xhtml, they set their 'class' attribute to be something defined in the css), and set their 'title' attribute to be the error string. They then call the superclass appendToResponse:inContext: code to actually generate the tag. As you can see, I need to be able to dynamically change various bound attributes, or I end up having to reimplement all of GSWTextField's behaviour in my subclass
Typical bindings for an element like this would be:
SomeField : ValidatedTextField {
/* normal TextField bindings apply */
errorDictionary = errorDict; // Bind my error dictionary
errorAttribute = "class"; // In the event of an error, we set 'class'
errorValue = "error"; // to 'error'
class = "textfield"; // the 'normal' class
title = "Enter some data here"; // The 'normal' title attribute
}
So, in 'normal' behaviour, the tage generated would be:
<input .... class="textfield" title="Enter some data here" />
but in the event of the error "Doofus! Enter some Data!" being set in the error dict for this field, we would get
<input ... class="error" title= "Doofus! Enter some Data!" />
I have a few components similar to this, and will be quite happy to donate them to the project once they're working properly.
Simon
|