On Jueves, 30 de Julio de 2009 23:24:12 G. Sobrinho escribió:
> Hello,
>
> I have a model named Customer with 4 fields which is required if customer
> is a company and 3 another fields if the customer is a person and some
> other fields common for both.
> The type is defined by a string field named customer_type which have
> 'company' or 'person'.
>
> How I can hide/show these fields by the select tag value?
>
>
> I think this:
>
> 1. Start with fields for company and person hidden
> 2. Select the type of customer
> 3. Show the fields for selected type
>
>
> This situation is very common for me. Actually I show all fields with a
> description saying it can be blank but this is not elegant for user.
>
>
> It can be developed using JS but, how? Suggestions?

I would use inheritance (STI) in that case, with a type column:
Customer
Company < Customer
Person < Customer

And then I would use two scaffolds, one for company and other for person, 
probably including a module with common active_scaffold configuration.

Anyway you can use onchange event in the select, and in the event show or hide 
the fields you want, using the clases for example:

function change_customer_type(event) {
        $$('.company_field_1-input, .company_field_2-input, 
.company_field_3-input, 
.company_field_4-input').each(function(item) {
                item.up('li').call(this.value == 'company' ? 'show' : 'hide');
        });

        $$('.person_field_1-input, .person_field_2-input, .person_field_3-
input').each(function(item) {
                item.up('li').call(this.value == 'person' ? 'show' : 'hide');
        });
}

-- 
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to