gerardobort / mongorilla

Mongorilla is a simple, clean, and powerful NodeJS based content moderator for MongoDB.
mongorilla.herokuapp.com
MIT License
79 stars 24 forks source link

Conditional fields #13

Open michael-may opened 10 years ago

michael-may commented 10 years ago

Dependent Fields

Dependent fields allow you to show or hide form elements based on a set of rules you define. This can be because it allows you to surface or remove certain inputs as they are, or are not, needed for completion of your form.

Currently, simple (on/off) dependent fields are supported.

To use this feature you need to apply some attributes to the dependent field's schema.
The object is formatted like this:

"yourDependentField" : {  
    ...  
    "depends" : {  
        "nameOfParentField" : {  
            "value" : "action"  
        }  
    }  
}  

The "value" key should match the value you want the parent to have in order to apply the "action" to the child form. "*" is supported as a wildcard to match any non-empty value.

The "action" value currently supports "show" and "hide".
Forms with the "show" action start off hidden.
Forms with the "hide" action start off visible.

gerardobort commented 10 years ago

Hi @michael-may,

Regarding this new feature, I think it's not as generic as I would want. I mean, this should cover your specific problematic, but even with more re-work, it's almost impossible to make it flexible in order to cover a good range of possibilities, for example:

I prefer to keep this outside the trunk... the reason is - It's pretty complex for the reduced functionality, and not so flexible.

In my opinion, the most convenient way to implement this, is to use the non-well documented, but cool way of customizing forms, models, and collections that this project support: Consists on putting a static version of the backend-generated JS file (an interceptor), and make it extend from that one but appending the .base extension. It's maybe hard to explain, but this example should tell you all: https://github.com/gerardobort/mongorilla/commit/54db22678ab54ebff9cdc4ddcc45cf17c6150689

That method is being used to tune the forms for editing built-in users and roles forms.

Thanks a lot for your collaboration on the project :)