0.1.6 • Published 11 months ago

odk-player v0.1.6

Weekly downloads
-
License
-
Repository
github
Last release
11 months ago

ODK Player

A React library to render ODK forms powered by Enketo Express šŸ”„āš”

ODK (Open Data Kit) is a free and open-source set of tools that help organizations author, field, and manage mobile data collection solutions. Enketo Express is a form engine that enables offline-capable, web-based form filling experiences. ODK Player is a React library that seamlessly integrates Enketo Express with React applications, allowing for easy rendering of ODK forms.

This library simplifies the process of incorporating ODK forms into React projects, providing a smooth and intuitive experience for both developers and users.

Prerequisites:

Before using ODK Player, ensure the following prerequisites are met: 1. Deployed Enketo Express Instance: You need to have a deployed instance of Enketo Express where your ODK forms are hosted. 2. Deployed OpenRosa-Compliant Server: ODK forms are typically served through an OpenRosa-compliant server. Ensure that you have a server, for example, Centro, properly deployed and configured.

How to Use:

To use ODK Player in your React application, follow these steps:

/* Sample Code snippet to incorporate ODK player */
// Import ODKPlayer and initializeODKPlayer from 'odk-player'
import ODKPlayer, { initializeODKPlayer } from 'odk-player';
import { useEffect } from 'react';

function App() {

  const onChange = (data) => {
    console.log("OnChange being executed on data: ", data)
  }

  const onSubmit = (data) => {
    console.log("OnSubmit called on data: ", data);
  }

  const onFailure = (data) => {
    console.log("onFailure called on data: ", data);
  }

  // Call initializeODKPlayer in useEffect with enketo express instance url and open rosa compliant server url.
  useEffect(() => {
    initializeODKPlayer(
        "ENKETO_EXPRESS_SERVER_URI", 
        "OPEN_ROSA_SERVER_URI"
        );
  }, [])

  return (
    <div className="App">
      <header className="App-header">

        {/* Finally load the ODKPlayer component in your app providing in the required props */}
        <ODKPlayer
          formId={"Nursing Form-Medical (CRP)"}
          height='100vh'
          width='50vw'
          offline={false}
          onChange={onChange}
          onSuccess={onSubmit}
          onFailure={onFailure}
        />
      </header>
    </div>
  );
}

export default App;

Props:

PropTypeDescriptionDefault
formIdstringThe id of the form to be renderedNone
heightstringHeight of the iframe to be rendered100vh
widthstringWidth of the iframe to be rendered100vw
offlinebooleanBoolean to decide whether form should work offline or notfalse
onChangefunctionCallback function to be executed on any form change eventNone
onSuccessfunctionCallback function to be executed on successful submission of formNone
onFailurefunctionCallback function to be executed on failure of form submissionNone

Ending Notes:

Thank you for choosing ODK Player! I hope this library makes integrating ODK forms into your React applications a breeze. Don't forget to star my repository if you find it useful!

🌟 Star us on GitHub: https://github.com/Samagra-Development/odk-player

Feel free to contribute, report issues, or suggest improvements. Happy coding! šŸ’»āœØ

0.1.6

11 months ago

0.1.5

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago