Custom component in formio.js
hi i would be wondering if u could tell me is there any way to add custom component to formio.js? i found a solution in angular version but couldn't found any in pure js version thanks
@amirmf check the code in this closed defects. Although it's being answered under Angular project, however, same steps can be applied in vanila JavaScript but your project should use TypeScript since the core of form.io (render engine) is being written by it.
@asalhani thanks for the response you mean we cant register any custom component if we use pure js renderer like below ???
Formio.createForm(document.getElementById('taskForm'), formioJSON,formOptions).then(function (form) { ....
Here is a Gist of how to create custom components. The registration of this component in the gist happens in Angular 5, but the concept is the same for just the vanilla.js renderer here.
https://gist.github.com/travist/59fa77086ec899e24992fc1508e61075
Awesome. Thank you @travist
@travist @Aiso786 does this line work for you? import { FormioForm } from 'formiojs/full'; if so what version are you using? I am using: "formiojs": "^3.5.3" and so far cannot find this formiojs/full
I just want to use a custom component and cannot as this code does not work! What am I missing here? Thanks.
Hello @Sigkill9 I'm doing like this with the latest version:
import { Formio, Form } from 'formiojs';
...
Formio.registerComponent('tabs', CustomTabsComponent);
@Aiso786 Thanks for the reply. I am using angular-formio and have installed formiojs using: npm i formiojs --save and the @types/formio is not a thing.
I have this problem?
Could not find a declaration file for module 'formiojs'. 'c:/angularapp/node_modules/formiojs/index.js' implicitly has an 'any' type.
Try npm install @types/formiojs if it exists or add a new declaration (.d.ts) file containing declare module 'formiojs';
You just need to
add a new declaration (.d.ts) file containing declare module 'formiojs';"
You just need to
add a new declaration (.d.ts) file containing declare module 'formiojs';"
Where? :(
You just need to
add a new declaration (.d.ts) file containing declare module 'formiojs';"
Can you please let me know where to add this file?
@Aiso786 @travist
From what I could find on this topic I added a new file. src/app/typings/index.d.ts
//index.d.ts
declare module 'formiojs'
Defined path to above file in tsconfig.json
"typeRoots": [
"node_modules/@types",
"./src/app/typings/index"
],
I have added the file and the error has gone away.
While debugging I see my component added to _components but when rendering the form I get Unknown component: mycustomcomponent
This is really the only thing holding up my implementation. So there is no straight forward way through the angular-formio lib to add a custom component? I tried using angular-formio/node_modules/formiojs But that fails too.. So ... stuck again.
Please help!
Stepping out of this thread as my issue is really about registering custom components in angular-formio and not vanilla JavaScript.
Based on the example below. Angular 5 + Form.io Custom Component
Hi fomiojs,
I am facing the same issue (being on 4.0.0-rc.22).
HOW TO REPRODUCE
-
Take the sample component Javascript as it is from: https://github.com/formio/formio.js/blob/v4.0.0-rc.22/app/examples/customcomponent.md
-
Add it to the builder:
mygroup: { title: "My Group", key: "mygroup", default: true, weight: 0, components: { checkmatrix: { title: "Check Matrix", group: "mygroup", key: "checkmatrix" } }, subgroups: [] }
CURRENT BEHAVIOUR
The component is displayed for selection and it is possible to add it to the form. However, there is no preview available:


Additional Note:
When taking the component code from https://gist.github.com/travist/59fa77086ec899e24992fc1508e61075 without altering it, not even the "unknown component" message is displayed. The console says "component.render is not a function".

Please provide a working example for a custom component. Thank you!
That component is designed for the 3.x branch. Here is the same one converted to the 4.x branch which has very different internals. https://github.com/formio/react-app-starterkit/blob/master/src/components/CheckMatrix.js
@randallknutson Thank you, this worked as expected! Also, it looks cleaner than the previous version.
I just had to add
Formio.Components.addComponent('checkmatrix', CheckMatrix);
at the end.