Extensible form logic based on lookup record...

Extensible form logic based on lookup record...

Just a tip on creating user input logic....
      
I often see deluge script in forms where people are trying to do a lot of dynamic show/hides based on a lookup record.. You know something like this...

if(field1 == "David Palmer" || field1 == "Wayne Palmer")
{
      show good;
}
else if(field1 == "Charles Logan")
{
      show bad;
}

OR a little better if they have a lot  of || statements they'll make a list

goodGuys = {"David Palmer","Wayne Palmer"};
if(field1 in goodGuys)
{
      show good;
}

BUT.. there's another way! 

Instead of hard coding your conditions to ds code, store the condition IN THE LOOKUP RECORD!

in the form you are referencing in your looking up.. Add some check boxes (bool fields) that match the field name you want to show or hide in the above parent form.. 

Example... 

form  lookup_form
{
    
    name
    (
        type  =  text
    )

    good
    (
        type  =  checkbox
        defaultvalue  =  false
    )

    bad
    (
        type  =  checkbox
        defaultvalue  =  false
    )

}

NOW, check of the desired values for each record.. 

now in your form you are using the lookup (the form using the show/hides)

//get your lookup record
lookup_record = lookup_form[name == field1.trim()];

//use the bool values to choose what to show or hide on your form
if(lookup_record.good)
{
      show good;
}
else{
      hide good;
}
if(lookup_record.bad)
{
      show bad;
}
else
{
      hide bad;
}

There! Now you don't have to update your form logic each time you want to add a record or change your business logic. Another GREAT BENEFIT is that you can even create highly dynamic workflows this way. Using this system allows you to dynamically decide what should be shown/performed/run on a parent record ON A RECORD TO RECORD BASIS. (Does that make sense?)

If you are a ds developer think of it as a shift in thinking...It's about giving the child record it's own commands to the parent form NOT just values that have to be evaluated at the parent. 

Example.. say we want to show a field in the parent form named  edit_date. We are talking about telling the parent form to SHOW the edit_date. WE DON'T NEED OR WANT a date field on the lookup form. We just want a dispatcher. 

-Stephen Rhyne
Owner 
Rhyne Design
@srhyne