I've tried to take one of the tags I'm using it in the class and
generalize it to contribute back. I have a couple of issues.
The tag itself is select-one-or-field-list. It's simply a select-one
and a field-list for the same object. If "New Object" is selected,
the field-list is displayed, otherwise it is disabled & hidden.
Here's the tag itself:
<def tag="select-one-or-field-list">
<div class="select-one-or-field-list">
<select-one include-none blank-message="&'New
'+this_field.titleize" class="select-one-or-field-list-select" merge
param />
<field-list param />
</div>
</def>
and the javascript:
(function() {
function selectChanged(el) {
if(el.value) {
$(el).siblings().each(function(elc) {
$(elc).setStyle({display: 'none'});
});
$(el).adjacent('input,select,textarea,button').each
(function(elc) {
elc.disabled = true;
});
} else {
$(el).siblings().each(function(elc) {
// FIXME: assumption of block display
$(elc).setStyle({display: 'block'});
});
// FIXME: maybe some inputs were previously disabled
$(el).adjacent('input,select,textarea,button').each
(function(elc) {
elc.disabled = false;
});
}
}
new HoboBehavior("div.select-one-or-field-list", {
events: {
"> select.select-one-or-field-list-select": {
":change": 'eventSelectChanged'
}
},
eventSelectChanged: function(ev, el) {
Event.stop(ev);
selectChanged(el);
}
});
document.observe("dom:loaded", function() {
$$("select.select-one-or-field-list-select").each(function(el)
{
selectChanged(el);
});
});
})();
Issues:
1) This doesn't work when the belongs-to is nil, I need to add <%
this.patient = Patient.new if this.patient.nil? %> in front of my
<select-one-or-field-list:patient /> invocation.
2) When the select-one-or-field-list invocation is inside of an input-
many, it's possible to get into a messed up state. For instance, if
you have two elements, and the top one has a selection and the bottom
one is on "new" and you click the "+", the new selection contains the
selection from the top element, but fields are displayed and copied
from the second field-list. I believe that this may be a bug in input-
many rather than my code.
Bryan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---