• Resolved Alberto

    (@albertobellipario)


    Hi.

    I need to have a check like this:
    If the difference between 2 dates is more than 8 years -> warning message appears.

    Eg. Today minus 15/02/2015 (date picker) -> Ehi, the difference is too much!

    Thanks in advance

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @albertobellipario

    Thank you very much for using our plugin.

    Assuming the date field is the fieldname1, you can insert a calculated field in the form and enter the equation:

    (function(){
    var d = DATEDIFF(TODAY(), fieldname1, 'yyyy-mm-dd', 'y')['years'];
    if(8 <= d) {
    return 'Ehi, the difference is too much!';
    }
    return d;
    })()

    Best regards.

    Thread Starter Alberto

    (@albertobellipario)

    It works perfect @codepeople.
    Another question.
    I’ve changed the last return condition.

    (function(){
    var d = DATEDIFF(TODAY(), fieldname1, ‘yyyy-mm-dd’, ‘y’)[‘years’];
    if(8 <= d) {
    return ‘Ehi, the difference is too much!’;
    }
    return ‘The difference is ok!’;
    })()

    Is there a way to format differently the two warning message?
    It’s a CSS matter? How use class or ID’s?

    EG.
    First warning -> Background red / Text white bold
    Second warning -> Background green / Text white bold

    Thanks in advance for eventual response.

    Plugin Author codepeople

    (@codepeople)

    Hello @albertobellipario

    Assuming the calculated field is the fieldname123, you can implement the equation as follows:

    (function(){
    var d = DATEDIFF(TODAY(), fieldname1, 'yyyy-mm-dd', 'y')['years'],
    tag = getField(fieldname123|n).jQueryRef().find('input');
    
    if(8 <= d) {
    
    tag.css({background:'red', color:'white', fontWeight:'bold'});
    return 'Ehi, the difference is too much!';
    }
    tag.css({background:'green', color:'white', fontWeight:'bold'});
    return 'The difference is ok!';
    })()

    I’m referring to the fieldname123 with the |n modifier (fieldname123|n). The plugin replaces the fields’ names in the equation with their corresponding values to use them in the mathematical operations. If you enter the field’s name with the |n modifier, you’re telling the plugin you want to use the field’s name directly and not its value.

    Best regards.

    Thread Starter Alberto

    (@albertobellipario)

    Works like charm.

    I have one last question, about condition.

    There’s a way to block filling out the form if the above condition is not “ok”?

    EG.

    If the condition result is ‘The difference is ok!’ the next fields should not appear or the page break does not appear or something like that.

    Plugin Author codepeople

    (@codepeople)

    Hello @albertobellipario

    You can apply IGNOREFIELD or ACTIVATEFIELD operations to activate or ignore fields. Ex.:

    (function(){
    var d = DATEDIFF(TODAY(), fieldname1, 'yyyy-mm-dd', 'y')['years'],
    tag = getField(fieldname123|n).jQueryRef().find('input');
    
    if(8 <= d) {
    
    ACTIVATEFIELD(fieldname123|n);
    ACTIVATEFIELD(fieldname321|n);
    
    tag.css({background:'red', color:'white', fontWeight:'bold'});
    return 'Ehi, the difference is too much!';
    }
    
    
    IGNOREFIELD(fieldname123|n);
    IGNOREFIELD(fieldname321|n);
    
    tag.css({background:'green', color:'white', fontWeight:'bold'});
    
    return 'The difference is ok!';
    })()

    Learn more about field managing operations by reading the following section in the plugin documentation:

    https://cff.dwbooster.com/documentation#managing-fields-module

    Best regards.

    Thread Starter Alberto

    (@albertobellipario)

    Thanks for response.
    Okay, the procedure is understandable and the guide quite clear.

    But what I am wondering is is it possible to prevent proceeding with the form unless you comply with the conditions set.

    EG.

    Condition #1 (if the date is less than or equal to 8 years difference, warning that you cannot proceed and inhibiting you from filling out the rest of the form)

    Condition #2 (if date is greater than 8 years difference, you may proceed to fill out the form

    Potentially there could be multiple conditions to apply, and if even one of them is not met, the form should be blocked from filling out.

    Is there a way to do this? Inhibit the Submit button and/or the Next Page?
    Like, have the warning appear as in the formula with ACTIVATEFIELD but simultaneously removing the ability to proceed.

    I hope I have explained myself better.

    Plugin Author codepeople

    (@codepeople)

    Hello @albertobellipario

    You can insert the rest of the fields into a DIV field, and activate or deactivate from the equation.

    The rest of fields would be enabled only if the condition is satisfied.

    Another alternative would be disable enable the fields by HTML attributes:

    (function(){
    var d = DATEDIFF(TODAY(), fieldname1, 'yyyy-mm-dd', 'y')['years'],
    tag = getField(fieldname123|n).jQueryRef().find('input'),
    fields = [fieldname1|n, fieldname2|n, fieldname3|n];
    
    if(8 <= d) {
    
    
    
    for(var i in fields){
    getField(fields[i]).jQueryRef().find(':input').prop('disabled', true);
    }
    
    tag.css({background:'red', color:'white', fontWeight:'bold'});
    return 'Ehi, the difference is too much!';
    }
    
    
    for(var i in fields){
    getField(fields[i]).jQueryRef().find(':input').prop('disabled', false);
    }
    
    tag.css({background:'green', color:'white', fontWeight:'bold'});
    
    return 'The difference is ok!';
    })()

    Best regards.

    Thread Starter Alberto

    (@albertobellipario)

    I admit the second solution it’s not clear to me.

    Maybe the first could be more practical to me.
    But the page break field is set outside a div.

    May I put a button in the div with the code to go “next” on the next page?
    And then set the function to show that div only if the rules are ok?

    Plugin Author codepeople

    (@codepeople)

    Hello @albertobellipario

    Yes, that’s possible.

    You can enter the style definition below through the “Customize Form Design” attribute in the “Form Settings” tab to hide the current next page buttons:

    #fbuilder .pbNext{display:none !important;}

    And then, you can insert a button field in the form, that you can configure as dependent, and enter the following code as its onclick event:

    jQuery('.pbreak:visible .pbNext').click();

    Best regards.

    Thread Starter Alberto

    (@albertobellipario)

    This solution set the rule for ALL the page break, right?
    So in every page I should set a button to do that, am I right?

    In alternative, it’s possible to apply the ACTIVATEFIELD | IGNOREFIELD function on the pbNext button on that specific page where the function is present?

    EG
    Page One – many anagraphical fields
    pbNext

    Page Two – technical fields with warning functions
    ACTIVATE pbNext if conditions set are met

    Plugin Author codepeople

    (@codepeople)

    Hello @albertobellipario

    The ACTICATEFIELD and IGNOREFIELD operations affect only the fields, and the next and previous buttons are not fields. If you want to CSS rule to the next buttons of specific pages, you should know that every page has assigned a unique class name (pb0, pb1, pb2, pb3, …). If you want to hide only the next page button on the first page, the style definition to use would be:

    #fbuilder .pb0 .pbNext{display:none !important;}

    Best regards.

    Thread Starter Alberto

    (@albertobellipario)

    This plugin is damn well written, if you’ll pardon the colorful expression.

    I’ll try that solution and give you an update about.

    Very, very thanks!

    Thread Starter Alberto

    (@albertobellipario)

    I’ve tried it with TWO conditions met and it functions very well!

    Thanks!!!

    Plugin Author codepeople

    (@codepeople)

    Excellent !!!!!

    Best regards.

    Thread Starter Alberto

    (@albertobellipario)

    Hello @codepeople.
    I managed to understand the syntax, at least in general terms, and came up with four conditions to enforce.
    
    But I clearly did not understand how to use the ACTIVATEFIELD and IGNOREFIELD functions properly.
    
    I have a dropdown with three choices. Each choice should activate a single calculated field and ignore the other two.
    Each calculated field, in turn, will contain a formula that will be exploited in a further calculated field.
    
    EG
    Dropdown: Choice1 | Choice 2 | Choice 3
    
    If I choose Choice 1, Calculated Field 1 should be activated and Calculated Fields 2 and 3 should be ignored.
    
    I wrote this function:
    
    Legend
    fieldname62 = Dropdown (3 choices = MI | CO | KA)
    fieldname66 = the CCF containing the function
    fieldname 63 | fieldname 64 | fieldname 65 = the conditional field to be activated and ignored
    
    (function(){
    var d = fieldname62,
    tag = getField(fieldname66|n).jQueryRef().find('input');
    
    if(fieldname62|v == 'MI') {
    
    ACTIVATEFIELD(fieldname63|n);
    IGNOREFIELD(fieldname64|n);
    IGNOREFIELD(fieldname65|n);
    
    return '';
    }
    
    else if(fieldname62|v == 'CO') {
    
    ACTIVATEFIELD(fieldname64|n);
    IGNOREFIELD(fieldname63|n);
    IGNOREFIELD(fieldname65|n);
    
    return '';
    }
    
    else if(fieldname62|v == 'KA') {
    
    ACTIVATEFIELD(fieldname65|n);
    IGNOREFIELD(fieldname63|n);
    IGNOREFIELD(fieldname64|n);
    
    return '';
    }
    
    else {
    
    return 'KO';
    }
    
    })()
    
    Where is wrong?
Viewing 15 replies - 1 through 15 (of 17 total)

The topic ‘Check on Date calculation’ is closed to new replies.