Skip to content
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

How to add a new tab in formio Angular? #554

Closed
ajaykumarsana opened this issue May 28, 2020 · 11 comments
Closed

How to add a new tab in formio Angular? #554

ajaykumarsana opened this issue May 28, 2020 · 11 comments
Labels

Comments

@ajaykumarsana
Copy link

ajaykumarsana commented May 28, 2020

Hi @travist ,
I been searching through the issues a lot for "Adding custom tab in form io",
Here i elaborate more what's query is ?

After drag any component this is how it appears, is it possible to add custom tab beside to any existing tab?
image

please help me. Thanks a lot

@travist
Copy link
Member

travist commented May 28, 2020

You just need to modify the "editForm" of that component and add another tab to the JSON of the tabs component there. Something like this maybe?...

const editForm = Formio.Components.components.textarea.editForm;
Formio.Components.components.textarea.editForm = function() {
  const form = editForm();
  const tabs = Formio.Utils.getComponent(form.components, 'tabs');
  tabs.components.push({
    key: 'custom',
    label: 'Custom',
    components: [
      ...
    ]
  });
  return form;
};

@travist travist closed this as completed May 28, 2020
@ajaykumarsana
Copy link
Author

ajaykumarsana commented May 29, 2020

Hi @travist
Thank you for the response, I'm having one issue here.
I.e when i try to print tabs in console custom tab shows but in UI custom tab not shown.
PFA.
image

Please help!!

@travist
Copy link
Member

travist commented May 29, 2020

My code above would have edited it for the Text Area component only. Here you are showing Text Field. Is that the issue?

@ajaykumarsana
Copy link
Author

Hi @travist
No, In your code i've made changes to textfield and applied.
Can you please provide a solution?

@ajaykumarsana
Copy link
Author

ajaykumarsana commented May 30, 2020

Hi @travist

I'll share my code snippet , please let me know where did i missed.
app.module.ts

import { AppConfig } from './formio-config';
import { FormioAppConfig} from 'angular-formio';
import { Components , Utils  } from 'formiojs';

const editForm = Components.components.textarea.editForm;
Components.components.textarea.editForm = function() {
  const form = editForm();
  const tabs = Utils.getComponent(form.components, 'tabs', true);
  tabs.components.push({
    key: 'custom',
    label: 'Custom',
    components: tabs.components[3].components
  });
  return form;
};

console.log(Components.components.textarea.editForm());

`

I've tried to print console.log(Components.components.textarea.editForm()); in the html where i use form-builder

both console.log statements showing custom tag which shown as below
image

But its not showing in UI :(

So, do we need to register or export editForm in above code to reflect in UI?
please help.
Thank you for your patience in reading my comments.

@travist
Copy link
Member

travist commented Jun 1, 2020

We will need some time to work up the prototype for this and provide a more detailed example (as well as try out your example). We may not get to this until later this week, but maybe someone from the community has done this and can provide code snippet.

@vlont
Copy link

vlont commented May 2, 2021

I am assuming that the logic of the formio works as if everything were Component. So I followed this concept and it worked here as follows:

 Formio.builder(document.getElementById('builder'), {},{
            //attachMode:'full',
            editForm: {
                textfield:[
                    { 
                       key: 'display', //Add in existing tab
                       components: [ 
                            { //Add custom field
                                title: 'Add field in existing Tab',
                                key: 'demo1',  
                                type: 'textfield', //field type, any existing and valid component
                                label: 'Add field in existing Tab Label',                            
                                input: true
                            },
                            { //Removing a existing field
                                key: 'description',
                                ignore: true
                            },
                        ]
                    },
                    { 
                        key: 'newTab', //ADD new custom TAB
                        label:"NEW Tab",
                        components: [  //ADD custom components in TAB
                            {
                                title: 'First Name',
                                key: 'firstname',  
                                type: 'textfield',
                                label: 'First Name',                            
                                input: true
                            },
                            {
                                title: 'List Names',
                                key: 'listnames',  
                                type: 'textarea',
                                label: 'List Names',                            
                                input: true
                            },
                        ]
                    },
                    {
                        key: 'api', //remove TAB
                        ignore: true
                    }      
                ]
            }

Captura de tela_2021-05-02_01-44-50
Captura de tela_2021-05-02_01-44-43
Captura de tela_2021-05-02_01-45-00

@vinayrdy966
Copy link

how to add click event here like in api tab, add another which add key and tab

@lane-formio
Copy link
Contributor

I'd suggest opening a new issue and possibly give some more information on what you are trying to do now?

@vinayrdy966
Copy link

thanks for quick response.
submitted new issue - #1068

@vinayrdy966
Copy link

How to add button event in formio? I'm adding custom button in angular formio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants