Comments (22)
I can't think why using it as an npm module would make a difference. We just tried including LForms in a React app we have (by adding the tags to the pre-built versions, not via npm) and both the form and the React app seemed to co-exist happily.
from lforms.
Although it is an npm package, it is intended for the browser, not to be run in Node.js. As with other npm packages like AngularJS or jQuery, you need to package up (and probably transpile) the files to be run in the browser (e.g. with webpack).
In our test in our React app, we just used the browser-ready version (which is built from the same files via webpack) by including the URLs from the website we've hosted those, as documented at http://lhncbc.github.io/lforms/#installation. (There are two URLs, one for the CSS and one for the JavaScript.) Note that the latest version is now 20.1.2. (The documentation says version 17, which was the latest then, but the same documentation applies.)
So, for your React app, unless you are already using webpack to package up other npm modules, I would not bother with the npm package for LForms, but just use the already webpacked, browser-ready version.
LForms does all of its stuff (rendering forms and exporting QuestionnaireResponses) in the browser.
I hope that helps. If I can find a way to make this more clear in the documentation, I will.
from lforms.
Do you have an example for React app? I am still confused how to integrate lforms to react component
from lforms.
Great, thank you for the feedback. I wanted to pursue this use-case but was not sure. Thanks for your prompt reply!
from lforms.
Hi, just wanted to get some advice and/or guidance on the implementation of this lforms NPM module within a React/Node.js project. I am continually met with errors when attempting to import this file in to a javascript file within a very small React project.
When attempting to install @types/lforms, I am given a 404 so it seems not to exist.
The module was installed in to my node modules folder via "npm install lforms --save" - it is correctly reflected in my package.json
I am also a bit confused by the examples on Runkit. I seem to continually hit a DOM/BOM related issue on the Runkit examples linked on the npm module page (see below):
@plynchnlm
In short, I am just looking for a bit of advice on the best practice for using this lforms npm module within a React application's paradigm. If you could show some examples from the implementation you mentioned that you did, which you mentioned in the comment above, then perhaps I could see where I am mistaken.
Could this be an issue with versioning in Node? I am currently using 10.16
Thank you and I look forward to hearing from you at your earliest convenience!
from lforms.
The error in your IDE indicates it is expecting the module to be TypeScript. It is just regular JavaScript. I don't use TypeScript, so I am not sure what to suggest, but my understanding was that JavaScript could be used with TypeScript code.
I had never seen the RunKit example before. I suspect it is autogenerated. The error you see there is the result of trying to require lforms from within Node. The lforms package works in a browser, and not within Node.js. Are you trying to use it server-side?
from lforms.
The error in your IDE indicates it is expecting the module to be TypeScript. It is just regular JavaScript. I don't use TypeScript, so I am not sure what to suggest, but my understanding was that JavaScript could be used with TypeScript code.
I had never seen the RunKit example before. I suspect it is autogenerated. The error you see there is the result of trying to require lforms from within Node. The lforms package works in a browser, and not within Node.js. Are you trying to use it server-side?
Yes, we were trying to leverage this npm package in a node environment. Our idea was to have handler functions call for FHIR questionnaire resources on the FHIR server, then use that LForm package's built-in methods to generate LForms data to display in React components. On top of this, also use the built-in methods to generate QuestionnaireResponse resources out of the input in to the LForm in the view.
I can't think why using it as an npm module would make a difference. We just tried including LForms in a React app we have (by adding the tags to the pre-built versions, not via npm) and both the form and the React app seemed to co-exist happily.
@plynchnlm How exactly did you implement this, if I may ask? In your latest response, you mention that the lforms package only works in a browser and not in a local node environment.
I appreciate your continued support, and look forward to hearing from you!
from lforms.
I have not tried integrating LForms in a React component. What we did try was including the pre-built versions using script/link tags (as described at http://lhncbc.github.io/lforms/#installation) in a page with a React app, and both the LForms display and the React app worked, but independently.
from lforms.
I can't think why using it as an npm module would make a difference. We just tried including LForms in a React app we have (by adding the tags to the pre-built versions, not via npm) and both the form and the React app seemed to co-exist happily.
Hi @plynchnlm
We are interested in using this library within our product (a react app), but in order to do so, we'd like to have it as an npm module as we really think it makes a difference because it enables/facilitates the testing. We are more than happy to help make the necessary changes to bundle it as an npm package! :)
Please. let us know what your thoughts are! This is a great library and I think making it more compatible with the other major frontend frameworks would make it even greater!
Thanks.
from lforms.
It is actually already an npm package: https://www.npmjs.com/package/lforms. This issue here is that it is intended to be run in the browser, and needs to be transpiled with webpack to something the browser can understand. If you are using webpack for your React app, it should be possible to pull in the lforms npm package. If you are not using webpack, well, I don't know but I suspect there will be some issues with getting it built. There is currently a mix of require and import statements, which I think cause a problem for some other build systems.
Also, be aware that we are going to release a rewrite in a couple of months, based on Angular, but the npm package will be a web component (which should be usable with React, or at least that was the goal).
from lforms.
I can't think why using it as an npm module would make a difference. We just tried including LForms in a React app we have (by adding the tags to the pre-built versions, not via npm) and both the form and the React app seemed to co-exist happily.
Please can you provide a simple example to illustrate your implementation. Thank you.
from lforms.
@lhcye Created this example of a React app using the lforms webcomponent (version 30.3.0): https://codepen.io/lhcye/pen/KKQbbwZ
For some reason the same example does not work in JSFiddle, but I guess that might have to do with how JSFiddle loads JavaScript libraries.
from lforms.
Closing, as the current version of lforms, which is a web component, does not have an npm version. We are hoping to get that working again, probably starting with an Angular component as a npm package. The issue is that when Angular builds the web component, it bundles all of the dependencies, and it does not make sense to publish bundled files as an npm package. Also, even if we did that, "import" statements to pull in the files might not work, depending on which build system you use. Anyway, the built files are available from https://clinicaltables.nlm.nih.gov/lforms-versions and can be downloaded from there, if you don't wish to run the build yourself.
from lforms.
Closing, as the current version of lforms, which is a web component, does not have an npm version. We are hoping to get that working again, probably starting with an Angular component as a npm package. The issue is that when Angular builds the web component, it bundles all of the dependencies, and it does not make sense to publish bundled files as an npm package. Also, even if we did that, "import" statements to pull in the files might not work, depending on which build system you use. Anyway, the built files are available from https://clinicaltables.nlm.nih.gov/lforms-versions and can be downloaded from there, if you don't wish to run the build yourself.
I saw your response and i really appreciate the effort. Still trying to get it to work though. Am using Next JS not Angular. I think my issue is at the installation phase. I Followed the guides but it still dosen't work. I keep getting 'LForms...' is undefined when i run 'LForms.Util.addFormToPage(formDefinition, 'myFormContainer', options)'.
from lforms.
How are you installing it?
from lforms.
Also, you did not mention whether you looked at the codepen example I posted above. Did you take a look at that?
from lforms.
1: Download the built zip. The latest version.
2: Extract the folder.
3: Save the folder to root directory of my NextJS project
4: Consume / import (whatever the term is) the scripts and css file in my pages using the script tag
5: In the JSX create a location to display the form
6: Run the 'LForms.Util.addForm......' with required arguments to display a form. Then all hell break loose.
7: Error: LForms is undefined.
from lforms.
Also, you did not mention whether you looked at the codepen example I posted above. Did you take a look at that?
I mentioned above that i looked at it. I also thanked you. Still trying to get it. Am more familiar with functional components. Pardon my green horns.
from lforms.
We're not familiar with NextJS, though we've heard of it. Perhaps you could share an example showing the problem on CodePen?
from lforms.
We're not familiar with NextJS, though we've heard of it. Perhaps you could share an example showing the problem on CodePen?
https://codesandbox.io/s/lhforms-ywh1xx?file=/pages/index.js
from lforms.
Looking at index.js in that example, it would seem that LForms is being used before you are returning the HTML that loads the LForms JS. Those files need to be loaded before LForms is used.
from lforms.
"LForms" probably needs to be "window.LForms". LForms is added to window when the js files are loaded.
I am not familiar with NextJs. You need to make sure all the LForms js files are loaded before you can use window.LForms.
from lforms.
Related Issues (20)
- e.toISOString is not a function error HOT 5
- Re: Using Lforms with existing angularJs app HOT 15
- Support for preferredTerminologyServer HOT 2
- Cannot find module 'jquery-ui/themescore.css'
- Got webpack missing module issue while writing test cases of Lhc form HOT 1
- Merging Questionnaire with QuestionnaireResponse do not hide items HOT 4
- Re: Customising the UI for the Lforms HOT 9
- Configuration option to prevent appending score value to answer options. HOT 14
- Building the Lforms library as npm package on local to test with host application. HOT 3
- Radio buttons are not checked within a vertical table HOT 2
- Adding form components. e.g. body site. HOT 6
- Not able to use lform NPM package in angular app. HOT 5
- Pagination HOT 1
- Lform is not validating fields when using time as datatype HOT 1
- ReferenceError: jQuery is not defined while running a jest unit test cases. HOT 1
- Questionnaire R4 population of copyright value HOT 1
- maxValue for type date HOT 2
- Exception seen when using local file instead of remote file for fhir/R4/lformsFHIR.min.js HOT 1
- Check Vailidity of LHC fhir form questionnaire before submit HOT 1
- Bad management of undefined HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lforms.