[html-formfu] Re $form->get_field with dynamic insert elements
kewei xiao
kewei.xiao at nald.ca
Fri Nov 2 11:58:47 GMT 2007
Carl, you were right, the textarea is inserted between existing fields.
I create a JS function called "loadInfo()" and is called on page load
event. In this JS function, first I check whether the desired radio
button is checked, if it is. I will use an Ajax call to get the
textarea inserted, since I only need to insert once, so I don't think
DOJO - repeatable will be necessary.
here is the JS function:
function loadInfo(status_id) {
var info_url = copyrightinfo_url;
var checkedValue;
status_element = $(status_id);
var children = status_element.childNodes;
for ( var i = 0; i < children.length; i++ ) {
if ( children[i].nodeType == 3 ) {
status_element.removeChild(children[i]);
}
}
new Ajax.Request(info_url, {
method: 'post',
onSuccess: function(transport) {
var response = transport.responseText;
var tmp = document.createElement("div");
tmp.innerHTML = response;
var list = status_element.childNodes;
for ( var i = 0; i < list.length; i++ ) {
if (list[i].firstChild.nodeType == 3 ) {
list[i].removeChild(list[i].firstChild);
}
if ( list[i].firstChild.checked ) {
checkedValue = list[i].firstChild.value;
if ( checkedValue == 2 && !$("resources") ) {
status_element.appendChild(tmp);
}
alert($('resource'));
}
}
}
} )
}
--------------------------------------------------------------------------------------------------------------------------------------
info_url will call the resource template to get the textarea create:
<textarea id="resources" name="resources" value="resources" cols=30
rows=6 onFocus="clearText(this.id)">
Enter resources here
</textarea>
--------------------------------------------------------------------------------------------------------------------------------------
So when page loads up, if the desired radio button is checked, the
textarea is inserted no problem. Then I use $form->get_field to get the
resource textarea, it doesn't recognize. I wonder if $form->get_field
works with dynamic insert element.
Thanks for your help
Ke Wei
More information about the HTML-FormFu
mailing list