-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Custom Component] - Is it possible to access the current instance of the Formio Component within the custom component? #1023
Comments
I had this question too, and no one answered. The solution I came up with was to create a global service, and within it there are methods for adding and viewing the main instance. In the formiobasecomponent component within the createRenderer function, I called the add method of the service I created.
In custom components, I injected this global service and viewed the instance that way. It worked, I hope it helps you. |
Can you explain more @adhonay how you are storing this and how you will get the same instance? It will be very helpful. |
Ignore the main and secondary instance part, in your case it will probably only be 1 instance.
|
Can you show the createRenderer class aswell how you are extending the class.? |
I am not able to get instance when i invoke setInstance(), or either calling createRenderer() from constructor in my custom component using reference from code snippet you provided , so could you please provide your custom component with the proper place where you are getting the instance ? or you can send across the files which have the running code. |
By extending MaterialComponent class i am able to get the instance of the custom component with setInstance() in one project but in another project without using angular material and considering typescript and angular(angular material excluded ) setup, which class i can extend/implement to achieve similar behavior? |
Hi @dinbtechit Did you find any solution? |
@pradeepsonisoni - I have not. I think the custom component has some issues with the way how it implemented updating the component value. Also, starting from version Formio/angular version 6.0.0 the custom components are being deprecated all together. So it may be worth forking the custom component code and adding it to your own angular project. That way, you will have more control over the code or at least that's what I am going to be doing to fix this issue. |
@dinbtechit Thank you for quick reply. |
createRenderer is a method already implemented by formio itself in the formiobasecomponent.ts component |
@adhonay If you are able to get the instance. you can share the code how you are implementing the FormioCustomComponent class. let us know because We are not getting the instance. |
FormioCustomComponent here is a simple interface, created in the Angular template.
You don't need anything more than: 1- Create the service as I sent above. 2- Insert the line below into the createRenderer function in formiobasecomponent.ts to send the instance. 3- In your CustomComponent, inject the service into the constructor and then wherever you want in the component, use the line: |
@adhonay If we have two instance of the same custom component. Is it working with two instance? I don't think so. |
@adhonay - isn't the formiobasecomponent class part the npm package, how did you manage to update the |
I cloned the git project and started implementing custom components from it. You can modify the createRenderer method because you have direct access to it. Line 108 |
Thanks @adhonay, that makes sense now. Actually, a better approach would be to fork the custom component and modify the logic there. |
Is it possible to access the current instance of the Formio Component within the custom component?
I would like to access the component because the customOptions are not accessible during initialization. Furthermore, dragging the component does not preserve any of the customOptions.
The text was updated successfully, but these errors were encountered: