• Resolved Ovidiu Zeicu

    (@ovidiu-zeicu)


    Hello there. Thank you for this great plugin.

    I’m building a revenue estimation form for car rental (people lists their own cars for rental). The calculation is based on car’s age, brand and model. I have a Brands dropdown with 26 entries, each with it’s own dependency Model dropdown (so I have 26 more dropdowns, only one being visible based on the Brand selected). Each Model dropdown have a different number of entries, each with it’s own value. The calculation needs to take into consideration the car’s age (under 3 years, over 3 years and over 5 years).

    I’ve come up with this formula (more fields are needed for final calculation, but I’ll deal with that later) that works well with one model(fieldname8) based on vehicle’s age (fieldname38).

    ((YEAR(TODAY())) – fieldname38) <= 3 ? (fieldname8*15*0.6) : (((YEAR(TODAY())) – fieldname38) <= 5 ? ((fieldname8*15*0.6)*0.75) : ‘Car is too old’);

    Now my problem is that I don’t know what would be the most efficient way of doing this for every other 25 fields. I’m hesitant in using the same formula for each of other Brand, because it will become a monster very fast.

    Another idea I had would be to set Brand’s value based on selected Model’s value. Is there a way of doing this? I’ve tried adding Model’s fieldname## as Brand value, but it doesn’t work. What can I use in Brand’s value field so it takes the value of it’s dependency?

    Or, if someone have a better way of doing this, I’m open to suggestions.

    Thank you.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @ovidiu-zeicu,

    There are some alternatives for using only two dropdown fields for brands and models instead of twenty-five dropdown fields for models.

    The first and recommended alternative is using the DropDown DS fields. The DS fields distributed with the Developer and Platinum plugin versions take their values from external data sources, like a database, a CSV file, a JSON structure, other submissions, or Advanced Custom Fields (https://cff.dwbooster.com/blog/2019/02/14/ds).

    For example, you can create a CSV file with three columns:

    brand, model, year

    And using only two DropDown DS fields for brands and models and a Number DS field for fabrication year.

    The second alternative is a little more complex than the previous one. The DropDown fields have the setChoices method. The setChoices method accepts an object as its parameter with “texts” and “values” attributes.

    So, you can create a javascript object, similar to:

    var db = {
    'bran1':['model_1_a', 'model_1_b', 'model_1_c'],
    'bran2':['model_2_a', 'model_2_b', 'model_2_c'],
    'bran3':['model_3_a', 'model_3_b', 'model_3_c'],
    'bran4':['model_4_a', 'model_4_b', 'model_4_c']
    };

    Now, assuming the DropDown fields for brand and models are the fieldname1 and fieldname2, respectively, you can implement a code similar to:

    getField(fieldname2|n).setChoices({texts:db[fieldname1], values:db[fieldname1]});

    The plugin replaces the field fields’ names by their corresponding values in the equations before evaluating them. However, using the |n modifier (Ex. fieldname2|n) tells the plugin you are referring to the field’s name and not their value.

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Get value from selected dependency’ is closed to new replies.