• Resolved chrisdias96

    (@chrisdias96)


    Hi there,

    I have a form that requires the user choosing from 3 dropdowns and calculates information & offers a downloadable pdf with it.

    The information displays fine, but I am having trouble implementing a button that redirects to a URL to a pdf on Google Drive. The button only appears if I have a pdf based on their choice. Not every choice between 3 dropdowns has a PDF.

    I’ve looked at other threads, I’ve tried hiding and showing the button while disabling dynamic equations but then I have no way to show the results of the calculator. And If I had a results button to show the calculations, it acts as the download button. I’m missing something, thanks.

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

    (@codepeople)

    Hello @chrisdias96

    I’ll try to describe the process with a hypothetical example:

    Assuming you have two dropdown fields: fieldname1 and fieldname2

    The fieldname1 includes the choices A and B, and the fieldname2 the choices X, and Y.

    If the user selects the choices A, and X, you want to redirect it to the URL:
    https://www.yourwebsite.com/path/first.pdf

    If the user selects the choices A and Y:
    https://www.yourwebsite.com/path/second.pdf

    For B and X:
    https://www.yourwebsite.com/path/third.pdf

    For B and Y:
    https://www.yourwebsite.com/path/fourth.pdf

    1. Insert a calculated field in the form and enter the equation:

    
    (function(){
    pdf_file='';
    if(AND(fieldname1=='A', fieldname2=='X')) pdf_file='https://www.yourwebsite.com/path/first.pdf';
    if(AND(fieldname1=='A', fieldname2=='Y')) pdf_file='https://www.yourwebsite.com/path/second.pdf';
    if(AND(fieldname1=='B', fieldname2=='X')) pdf_file='https://www.yourwebsite.com/path/third.pdf';
    if(AND(fieldname1=='B', fieldname2=='Y')) pdf_file='https://www.yourwebsite.com/path/fourth.pdf';
    })()
    

    Since the calculated field is used as an auxiliary field, you can hide it by ticking a checkbox in its settings.

    2. Insert a button in the field with the following piece of code as its onclick event:

    
    if(pdf_file.length) redirectToURL(pdf_file);
    

    And that’s all.
    Best regards.

    Thread Starter chrisdias96

    (@chrisdias96)

    Thanks,

    That works but now I have other issues.
    If I have 2 buttons, one to calculate and another to download, they both act as an update button and both have the ability to download.

    Also, I want to hide the download button if there is no pdf, what’s the line of code for that?

    Reference: https://bit.ly/2ZO8m6N

    Thread Starter chrisdias96

    (@chrisdias96)

    Got it working thanks.

    Thread Starter chrisdias96

    (@chrisdias96)

    Hello,

    I have a continuation.

    I want to hide the download button if there is no pdf_file available.
    How do I go about showing or hiding depending on if a link is available?

    Plugin Author codepeople

    (@codepeople)

    Hello @chrisdias96

    Continuing with the hypothetical example, you can assign a custom class name to the download button, for example, download-button

    The class names are assigned to the fields through their attributes: “Add CSS Layout Keywords.”

    And then, you can edit the equation as follows:

    (function(){
    pdf_file='';
    if(AND(fieldname1=='A', fieldname2=='X')) pdf_file='https://www.yourwebsite.com/path/first.pdf';
    if(AND(fieldname1=='A', fieldname2=='Y')) pdf_file='https://www.yourwebsite.com/path/second.pdf';
    if(AND(fieldname1=='B', fieldname2=='X')) pdf_file='https://www.yourwebsite.com/path/third.pdf';
    if(AND(fieldname1=='B', fieldname2=='Y')) pdf_file='https://www.yourwebsite.com/path/fourth.pdf';
    
    if(pdf_file == '') jQuery('.download-button').hide();
    else jQuery('.download-button').hide();
    })()

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Conditional Download Button’ is closed to new replies.