Jump to content

Vitalikssssss

Caspio Evangelist
  • Content Count

    508
  • Joined

  • Last visited

  • Days Won

    51

Posts posted by Vitalikssssss

  1. Hi @kpcollier,

    Try this code:
     

    <script type="text/javascript">
    
    document.addEventListener('DataPageReady', function (event) {
    
    let v_fields = ["Labor1_Rate", "Labor1_Hours", "Labor2_Rate", "Labor2_Hours", "Labor3_Rate","Labor3_Hours",
    "Labor4_Rate", "Labor4_Hours", "Labor5_Rate", "Labor5_Hours", "Labor6_Rate", "Labor6_Hours", "Labor7_Rate", "Labor7_Hours",
    "Labor8_Rate", "Labor8_Hours", "Labor9_Rate", "Labor9_Hours", "Labor10_Rate", "Labor10_Hours", "Labor11_Rate", "Labor11_Hours",
    "Labor12_Rate", "Labor12_Hours", "Labor13_Rate", "Labor13_Hours", "Labor14_Rate", "Labor14_Hours", "Labor15_Rate", "Labor15_Hours",
    ]; 
    
    let t_field = ["Labor1_Total", "Labor2_Total", "Labor3_Total", "Labor4_Total", "Labor5_Total", "Labor6_Total", 
                    "Labor7_Total", "Labor8_Total", "Labor9_Total", "Labor10_Total", "Labor11_Total", "Labor12_Total",
                    "Labor13_Total", "Labor14_Total", "Labor15_Total",]; 
    
    let sub_total = document.getElementById("InsertRecordLabor_SubTotal");
    
    sub_total.value = 0;
    
    let v_state = [];
    
    let t_state = [];
    
    v_fields.forEach(function(el) {
    
        if (el !== null) {
                v_state.push(document.getElementById("InsertRecord"+el));
        }
     });
    
    v_state.forEach(function(el){
        if (el !== null) {
                el.addEventListener("keyup", calculate);
                
    
        }
    });
    
    t_field.forEach(function(el) {
    
       if (el !== null) {
               t_state.push(document.getElementById("InsertRecord"+el));
       }
    });
    
    
    function calculate() {
    
        let i = 0;
    
        t_state.forEach(element => { 
    
            if (element !== null) {
                
                element.value = ((!isNaN(v_state[i].value)) ? v_state[i].value : 0) *
                
                            ((!isNaN(v_state[i+1].value)) ? v_state[i+1].value : 0);
                
                            sub_total.value = +sub_total.value + +element.value;
                            console.log(sub_total.value);
                i+=2;
        }
        
            
        });
    }
    
    
    
    });
    
    </script>

     

    This code should resolve the issue.

    Regards,

    Vitalikssssss

  2. Hi @kpcollier,

    You can use "start with" type of comparison in query selector like this:

    document.querySelector("input[id^='InsertRecordPrimary_Address']").value;

    The whole code would look like this:

    <script type="text/javascript">
    
    document.addEventListener('DataPageReady', function (event) {
    
    function f_address(){
    
        if(document.getElementById('cbParamVirtual4').checked) {
    
    document.querySelector("input[id^='InsertRecordBilling_Address']").value = document.querySelector("input[id^='InsertRecordPrimary_Address']").value;
    
    document.querySelector("input[id^='InsertRecordBilling_City']").value = document.querySelector("input[id^='InsertRecordPrimary_City']").value;
    
    document.querySelector("input[id^='InsertRecordBilling_State']").value = document.querySelector("input[id^='InsertRecordPrimary_State']").value;
    
    document.querySelector("input[id^='InsertRecordBilling_Zip']").value = document.querySelector("input[id^='InsertRecordPrimary_Zip']").value;
    
    } else {
    
    document.querySelector("input[id^='InsertRecordBilling_Address']").value = "";
    
    document.querySelector("input[id^='InsertRecordBilling_City']").value = "";
    
    document.querySelector("input[id^='InsertRecordBilling_State']").value = "";
    
    document.querySelector("input[id^='InsertRecordBilling_Zip']").value = "";
    
    }
    
    }
    
    document.getElementById('cbParamVirtual4').onclick= f_address;
    
    });
    
    
    </script>

     

    Regards,

    vitalikssssss

  3. Hi @DesiLogi,

    It would be more challenging to get display values instead of ID`s.

    I have found a solution which might work for your case.

    Basically, you would need to add additional Calculated field to your Gallery report Datapage and modify the JS.

    1. Calculated Field will use SQL in order to get string of all lookup values. 

    You can  use the following expression:

    STUFF((SELECT CAST(', ' + Name AS VARCHAR(MAX)) 
             FROM a_1 
             FOR XML PATH ('')), 1, 2, '')

    Where:

    • a_1 name of your Table which stores lookup values,
    • "Name" - name of the field which stores lookup values.

    You can hide this calculated field from a user by placing HTML blocks above and below the field. Also, you should place the following code in HTML block:

    top HTML block

    <div style="display:none;">

    bottom HTML block

    </div>

    make sure you disable HTML editor.

    2. Finally, place the following JS code into HTML block in order to show Listbox of display values:

    <div id="demo[@field:Record_ID#]"></div>
    
    <script type="text/javascript">
        
    document.addEventListener('DataPageReady', function (event) {
    
    let list_string, arr_string, arrLen, text, i, list_values, arr_result;
    
    list_string = "[@field:Text]";
    list_values = "[@calcfield:1]";
    
    arr_string = list_string.split(',');
    arr_values = list_values.split(',');
    
    arr_result = arr_string.map( value => value-1);
    
    debugger;
    arrLen = arr_result.length;
    
    text = "<ul>";
    
    for (i = 0; i < arrLen; i++) {
        
        console.log(arr_result[i]);
    
        text += "<li>" + arr_values[arr_result[i]] + "</li>";
    }
    
    text += "</ul>";
    
    document.getElementById("demo[@field:Record_ID#]").innerHTML = text;
    
    });
    </script>

     
    Hope this helps.

    Regards,

    vitalikssssss

  4. Hi @Prophecy,

    First, you should use Caspio`s build-in event handlers (e.g. Datapage ready).

    Second, you should change the way how you trying to reference calculated field.

    You use Submission form along with Calculated Value form element as I have understood.

    If my assumption is correct than you can use the following code:

    <div id="Section_2" style="display:none;">
    
    Some text Section 2
    
    </div>
      
    <div id="Section_3" style="display:none;">
    
    Some text Section 3
    
    </div>
      
    <div id="Section_4" style="display:none;">
    
    Some text Section 4
    
    </div>
    
    <-- This code goes into Datapage footer-->
      
    <script type="text/javascript">
    
    document.addEventListener('DataPageReady', function (event) {
    
    let calcField 
    
    setInterval( function() {
      
      calcField = document.querySelector("[id^='InsertRecordText']").innerHTML; //insert your field name i.o. Text
      
      Hide(calcField); 
    
    }, 2000); //interval of function execution 2 sec
    
    function Hide (calcField) {
    
    if (calcField < 33) {
    
      document.getElementById('Section_2').style.display = 'block';
      document.getElementById('Section_3').style.display = 'none';
      document.getElementById('Section_4').style.display = 'none';
    } else if (calcField < 66 && calcField >= 33 ) {
    
      document.getElementById('Section_2').style.display = 'none';
      document.getElementById('Section_3').style.display = 'block';
      document.getElementById('Section_4').style.display = 'none';
    
    } else if (calcField < 100 && calcField >= 66) {
    
      document.getElementById('Section_2').style.display = 'none';
      document.getElementById('Section_3').style.display = 'none';
      document.getElementById('Section_4').style.display = 'block';
    
    }
    }       
    });
    </script>

    Hope this helps.

    Regards,

    vitalikssssss

  5. Hi @NiceDuck,

    It will not be possible to capture who has deleted the record with Triggered action.

    I would recommend using another Datapage with auto-submit JS which would insert a record to the history log table.

    You configure your page to re-direct after record delete to the submission form  and also pass parameters on exit to the submission form.

    However, this workflow would work only if you delete records from Details page.

    Hope this helps.

    Regards,

    vitalikssssss

     

  6. Hi @DesiLogi,

    Try using the following script in the Footer of the Datapage:

    <script type="text/javascript">
        
     function f_listbox(v_state) {
      if ( v_state.indexOf(",") > 0 ) {
       for (let i=0 ; i < o_state.options.length; i++ ) {
        if(o_state[i].value == v_state) {
         o_state.remove(i);
         break ;
        }
       }
       let o_st = v_state.split(", ") ;
       for (let j=0 ; j < o_st.length; j++) {
        for (let i=0 ; i < o_state.options.length; i++ ) {
         if(o_st[j]== o_state.options[i].value){
          o_state.options[i].selected = true ;
          break ;
         } 
        }
       }
      }
     }
    
    document.addEventListener('DataPageReady', function (event) {
    
    let v_state = ["CompanyName", "FirstName", "LastName"]; //Field names goes here 
    let o_state = [];
    
     v_state.forEach(function(el) {
        if (el !== null) {
                o_state.push(document.getElementById("EditRecord"+el));
        }
     });
    
     o_state.forEach(function(el){
    
        if (el !== null) {
            el.multiple = true;
        }
     });
    
    f_listbox(v_state);
    
    });
    
    </script>

     

  7. Hi @DesiLogi,

    As I have understood you would like to have something similar to this:

    IrM691l.png

    You would need a bit of JS to achieve this. Initially I have used this post as the inspiration for the following JS code which produce list of items.

    <!––Place this code into HTML block.-->
    
    <div id="demo[@field:Record_ID#]"></div> <!––[@field:Record_ID#] is a unique indentifier of the record-->
    
    <script type="text/javascript">
        
    document.addEventListener('DataPageReady', function (event) {
    
    let list_string, arr, arrLen, text, i;
    
    list_string = "[@field:Text]"; //field where you store comma delimited string
    
    arr = list_string.split(',');
    arrLen = arr.length;
    
    text = "<ul>";
    for (i = 0; i < arrLen; i++) {
      text += "<li>" + arr[i] + "</li>";
    }
    text += "</ul>";
    
    document.getElementById("demo[@field:Record_ID#]").innerHTML = text; // use unique indentefier of the record i.o. [@field:Record_ID#]
    
    
    });
    </script>

    Hope this helps.

    Regards,

    vitalikssssss

  8. Hi @Andrew,

    I am afraid that you will not be able to parse multi-select Listbox parameter in your second Datapage, however you should be able to achieve the desired logic of filtering if you use search form with multi-select Listbox on your second Datapage. You can create a Javascript code which would click on the "Search" button within 2nd Datapage after user clicks on "Search" on the 1st Datapage and also hide a Search form from the 2nd Datapage.

    Here is JS code which I have used:

    1. Wrap a Search from from 2nd Datapage with the following:

    Header:

    <div id="search_form">

    Footer:

    </div>

    2.  This code should be placed in the Footer of the 2nd Datapage.

    <script type="text/javascript">
        
    document.addEventListener('DataPageReady', function (event) {
    //hide a search form from 2nd DP
    document.querySelector("#search_form").style.display = "none";
    
    let buttons = document.querySelectorAll(".cbSearchButton");
    
    //adding onclick event listener to the 1st DP search form
      
    buttons[0].addEventListener("click", ()=> {
        
        //clicking on search button of 2nd DP with a delay
      
        setTimeout(()=>{buttons[1].click();}, 500)
    
    
    }, false);
    
    });
    </script>

     

    Hope this helps.

    Regards,

    vitalikssssss

  9. Hi @CHlux,

    I do not think you will be able to transfer file via Zapier.

    Perhaps you should check WebMerge REST API which should have a method to post a file into external database such as Caspio.

    Caspio REST API supports file transfer. You can check Swagger documentation in order to find the method for file transfer.

    I would recommend Professional service department of Caspio if you are not familiar with REST API.

    Hope this helps.

    Regards,

    vitalikssssss

     

     

  10. Hi @DesiLogi,

    You can use window.open() function for your second URL and setTimeout for the first URL in order to refresh the page after the second URL opens.

    <script type="text/javascript">
    document.addEventListener('DataPageReady', function (event) {
    
    window.open('[@field:Second_URL]');
    
    setTimeout(function(){ window.location.href = '[@field:First_URL]'; }, 3000); 
    
    });
    </script>

    Please note that pop-ups are blocked by the default in most commonly used web-browser and a user must allow pop-ups prior it will be opened by JS.

    Hope this helps.

    Regards,

    vitalikssssss

  11. Hi @DesiLogi,

    I am 100% sure that you have also received an error in the browser Console  before form submit.

    flUpMN8.png

    This error means that Value attribute can be set to an empty string only.

    I believe this is a security restriction of the browser.

    I can suggest storing a URL of the picture i.o. storing a file in the table.

    Hope this helps.

    Regards,

    Vitalikssssss

     

×
×
  • Create New...