angular icon indicating copy to clipboard operation
angular copied to clipboard

How to add a new tab in formio Angular?

Open ajaykumarsana opened this issue 6 years ago • 11 comments

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

ajaykumarsana avatar May 28 '20 13:05 ajaykumarsana

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 avatar May 28 '20 14:05 travist

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!!

ajaykumarsana avatar May 29 '20 06:05 ajaykumarsana

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

travist avatar May 29 '20 14:05 travist

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

ajaykumarsana avatar May 29 '20 16:05 ajaykumarsana

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.

ajaykumarsana avatar May 30 '20 11:05 ajaykumarsana

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.

travist avatar Jun 01 '20 20:06 travist

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

vlont avatar May 02 '21 04:05 vlont

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

vinayrdy966 avatar Apr 03 '24 16:04 vinayrdy966

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

lane-formio avatar Apr 03 '24 18:04 lane-formio

thanks for quick response. submitted new issue - https://github.com/formio/angular/issues/1068

vinayrdy966 avatar Apr 03 '24 19:04 vinayrdy966

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

vinayrdy966 avatar Apr 04 '24 21:04 vinayrdy966