Transfer from CAPI Webview to logic

Discussions about CSEntry
htuser
Posts: 590
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Transfer from CAPI Webview to logic

Post by htuser » January 26th, 2022, 11:48 am

Hi Alex,
This was a mistake from my own part since i think that, by default, jquery and bootstrap was linked by default to any webview call. RIght now the first part is definitely solved.
Please, for a such function

Code: Select all

function ValidateFirstName(inputId) { 
    var result =document.getElementById(inputId).value;

	//CSPro.runLogicAsync(`ValidationPrenom("${$('#Prenom').val()}");`); 
	CSPro.runLogicAsync(`ValidationPrenom(" .... ";`); 
	//CSPro.invokeAsync("ValidationPrenom", JSON.parse (...)); 
 }
what's the exact syntax for passing the result Var as an argument to both, CSPro.invokeAsync or CSPro.runLogicAsync?

Thanks,
G.VOLNY, a CSProuser from Haiti, since 2004

alex_izm
Posts: 17
Joined: December 9th, 2016, 11:31 am

Re: Transfer from CAPI Webview to logic

Post by alex_izm » January 26th, 2022, 5:30 pm

Here is the JS syntax for calling the function with runLogic and invokeAsync with both jQuery selector function and vanilla JavaScript/DOM:

Code: Select all

        //jQuery/runLogicAsync
        function ValidateFirstName(inputId) {
            CSPro.runLogicAsync(`ValidationPrenom("${$("#" + inputId).val()}");`);
        }

        //jQuery.invokeAsync
        function ValidateFirstName(inputId) {
            CSPro.invokeAsync("ValidationPrenom", JSON.stringify({ "Prenom": $("#" + inputId).val() }));
        }

        //Vanilla JS/runLogicAsync
        function ValidateFirstName(inputId) {
            var result = document.getElementById(inputId).value;
            CSPro.runLogicAsync(`ValidationPrenom("${result}");`);
        }

        //Vanilla JS/invokeAsync
        function ValidateFirstName(inputId) {
            var result = document.getElementById(inputId).value;
            CSPro.invokeAsync("ValidationPrenom", JSON.stringify({ "Prenom": result }));
        }
Alex

htuser
Posts: 590
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Transfer from CAPI Webview to logic

Post by htuser » January 27th, 2022, 3:08 pm

Dear Alex,
Thanks again for your support. Having the way to run any Javascript in CSPro apps and retrieve the return to CSPro logic is a great achievement.
Among others, CSPro users will be able to design apps displaying multiple questions per screen on Android using the same UI on Windows and Android.
Also, this demonstrate that we're not too far of having ability to design CAWI apps.

The JS-CSPro api allow the call of CSPro logic functions to JS, not the inverse. But, with your help we can do it: call the result of any JS function to CSPro logic.
Even if we would like to have a more convenient way to add any JS libs as external scripts and call them more directly in logic, until, technically we can use the CAPI webview part for any complexes JS call to Logic.

Your explanations made it very clear to everyone who want to fully use JS-CSPro interface.

However, even if Greg explain how to return the value of async CSPro API call to Javascript,
viewtopic.php?f=1&t=4734
I've some issue with this. Please take a look in the demo ap sent to you for more help and support.

Thanks in advance for your support
G.VOLNY, a CSProuser from Haiti, since 2004

Post Reply