Uniface User Forum

 View Only
  • 1.  React button calling Uniface code

    Posted 07-30-2021 12:40

    Hi,

    I am using React, which is a library for JavaScript to design front-ends.

    I am wondering if I can make a JavaScript/React button that calls JavaScript code that I have written in Uniface.

    For example, to make a React button call a JavaScript function named getEmployees(), you would write the following code:

    <button onClick={getEmployees}>Show employees</button>

    How can I call code that I have written in Uniface, from my JavaScript application (which is not in Uniface)?



  • 2.  RE: React button calling Uniface code

    ROCKETEER
    Posted 07-30-2021 13:49

    Hi Jurjen,

    Most people find building a UI in a JavaScript framework like React or Angular harder than building the UI in Uniface DSP component (which binds the data to the HTML by ID and does all the synchronization, as well as providing server-side triggers and JavaScript webtriggers), but if you want to do that you can. Your question is more about JavaScript/React however. 

    In vanilla JavaScript you can add an onClick event to a button in a number of ways, e.g. 

      var btn = document.getElementById("button");
      btn.onclick = function() {
    // your code here
    }

    or use the onClick attribute to call a method in your JavaScript code rather than the anonymous function I declared above, e.g. 

      <button onClick="getEmployees();">Show Employees</button>

    Your JavaScript code (e.g. getEmployees) would then use the Uniface API to instantiate components, activate operations, and/or directly access data: APIs: JavaScript (uniface.com). I addressed the question of how to include the Uniface JavaScript API in response to one of your earlier questions.

    Regards,

    David