• Resolved mpbaweb

    (@mpbaweb)


    Hi. Me again
    My form allows the user to choose a membership category e.g.
    Adult
    Junior
    Pensioner

    I’m trying to figure out how to validate (apply boundaries to) the date range in the date of birth field for the category chosen e.g.
    Adult must be >= 19 and < 65 years
    Junior must be <= 18 years
    Pensioner must be >= 65 years

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

    (@codepeople)

    Hello @mpbaweb

    There are different alternatives.

    * You can insert a different Date/time field in form with the corresponding Max date defined, associated to the corresponding choice in the “Membership Category” field (DropDown or radio button)

    * Or you can use only one Date/Time field and check it through the equation associated to the calculated field. For example, using the Developer version of the plugin that is distributed with the Date/Time operations module, and assuming that the date/time field is the fieldname2, the category field the fieldname1:

    
    (function(){
    var y = DATEDIFF(fieldname2,TODAY(),'dd/mm/yyyy','y')['years'];
    if(18 < y && fieldname1 == 'Junior') return 'Invalid date';
    if((y <=18 || 65 <= y) && fieldname1 == 'Adult') return 'Invalid date';
    if(y < 65 && fieldname1 == 'Pensioner') return 'Invalid date';
    
    /** The other operations in the equation here **/
    })()
    

    * Another alternative would be modify the “Max” attribute in the date/time fields programmatically (the following link can give you an idea https://cff.dwbooster.com/documentation#relationship-between-date-fields)

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Validate age’ is closed to new replies.