formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

You can pass an options object to the builder component and set ignore: true on the fields you don't want. Here is an example:

Open ranjanitechleaf opened this issue 7 years ago • 13 comments

You can pass an options object to the builder component and set ignore: true on the fields you don't want. Here is an example:

http://formio.github.io/formio.js/app/examples/custombuilder.html

Originally posted by @randallknutson in https://github.com/formio/formio.js/issues/1200#issuecomment-485831686

Hi I cannot find the options object, please help us to fix that. could you provide one example for an option.

ranjanitechleaf avatar Apr 24 '19 12:04 ranjanitechleaf

@ranjanitechleaf Hi you can pass options object like this. Formio.builder(document.getElementById('builder'), { components: formioComponents }, FormBuilder.customForm).then(function (builder) {});

FormBuilder.customForm is an options object which will consist the builder and editForm attributes. EditForm attribute will handle the configuration of that field Modal, ignore: true will hide the field from Modal.

customForm = {
        builder: {
            ...
        },
        editForm: {
            textfield: [
				{
					key: 'display',
					ignore: false,
					components: [
						{
							key: 'prefix',
							ignore: true
						},
						{
							key: 'suffix',
							ignore: false
						}
					]
				}
		
			]
            }
    }

Thanks,

noman115pk avatar Apr 25 '19 10:04 noman115pk

Thank you soo much , its working fine

ranjanitechleaf avatar Apr 25 '19 10:04 ranjanitechleaf

hi. i want to ignore any component in custom tab of base component. but how?

image

i want to ignore (lable and placeholder ) of (text field) component of ( basic Components) only. thank.

contona68 avatar Jan 07 '20 14:01 contona68

@contona68 you want to ignore label and placeholder or all other fields but not label and placeholder? (I believe you need a label field)

customForm = {
        builder: {
            ...
        },
        editForm: {
            textfield: [
				{
					key: 'display', // the tab
					ignore: false,
					components: [ // the fields you want to ignore
						{
							key: 'placeholder',
							ignore: true
						},
					]
				}
		
			],
			select:[
				{
					key: 'data', // the data tab
					ignore: false,
					components: [ // the fields you want to ignore
						{
							key: 'dataSrc',
							ignore: true
						},
					]
				}
            }
    }

for all field keys/tabs, look at the source code: https://github.com/formio/formio.js/tree/master/src/components

marcus-at-localhost avatar Jan 07 '20 20:01 marcus-at-localhost

Thanks for your answer

but i want to custom display tab in textFiels component in Basic component of builder only

not all textField in another .

image

contona68 avatar Jan 08 '20 06:01 contona68

@contona68 could you post a jsfiddle/codepen of your case with your configuration? (Feel free to for from this: https://codepen.io/localhorst/pen/KKwQoNM) With editForm.textfield set, you only affect the textfield component. What does (3) mean in your illustration? you want to remove that only in the textField component?

image

marcus-at-localhost avatar Jan 08 '20 07:01 marcus-at-localhost

<script>
		var custom = {
			title: 'User Fields',
			weight: 10,
			components: {
				firstName: {
					title: 'First Name',
					key: 'firstName',
					icon: 'terminal',
					schema: {
						label: 'First Name',
						type: 'textfield',
						key: 'firstName',
						input: true,
						
					}
				},
				lastName: {
					title: 'Last Name',
					key: 'lastName',
					icon: 'terminal',
					schema: {
						label: 'Last Name',
						type: 'textfield',
						key: 'lastName',
						input: true
					}
				},
				email: {
					title: 'Email',
					key: 'email',
					icon: 'at',
					schema: {
						label: 'Email',
						type: 'email',
						key: 'email',
						input: true
					}
				},
				phoneNumber: {
					title: 'Mobile Phone',
					key: 'mobilePhone',
					icon: 'phone-square',
					schema: {
						label: 'Mobile Phone',
						type: 'phoneNumber',
						key: 'mobilePhone',
						input: true
					}
				}
			}
		};
	
		window.onload = function() {
			Formio.builder(document.getElementById('builder'), {}, {
				builder: {
					basic: false,
					advanced: false,
					data: false,
					layout: {
						components: {
							table: false
						}
					},
					premium: false,
					customBasic: {
						title: 'Basic Components',
						default: true,
						weight: 0,
						components: {
							videoEditor: true,
							checkmatrix: true,
							textfield: true,
							textarea: true,
							email: true,
							phoneNumber: true
						}
					},
					custom: custom
				},
				editForm: {
					textfield: [
						{
							key: "api",
							ignore: true,
						},
						{
							key: "display",
							ignore: false,
							components: [
								{
									key: "label",
									ignore: true
								},
								{
									key: "tooltip",
									ignore: true
								},
								{
									key: "widget",
									ignore: true
								}
							]
						}      
					]
				
			    }
			}).then(function(builder) {
				builder.on('change', function(schema) {
					console.log(schema)
				});
				builder.on('saveComponent', function() {
					console.log(builder.schema);
				});
			});
		};
	</script>

i create custom cumponet and used textFeild component in it . if i ignore textfield all component that used textfield type be ignore. but I want to ignore textfield in my cutomed in display tab only not all.

contona68 avatar Jan 08 '20 09:01 contona68

@contona68 you mean that custom components like firstName, lastName that are based on textfield components are affected by editForm.textfield definitions as well?

marcus-at-localhost avatar Jan 08 '20 11:01 marcus-at-localhost

yes I want to ignore and customation display tab in firstName, lastName only. but by this config

   	editForm: {
				textfield: [
					{
						key: "api",
						ignore: true,
					},
					{
						key: "display",
						ignore: false,
						components: [
							{
								key: "label",
								ignore: true
							},
							{
								key: "tooltip",
								ignore: true
							},
							{
								key: "widget",
								ignore: true
							}
						]
					}      
				]
			
		    }

all component with type of textfield is affected by editForm.textfield.

contona68 avatar Jan 08 '20 12:01 contona68

You are right, custom fields based on another field seem to inherit the properties. https://codepen.io/localhorst/pen/qBExMqz

I'm not sure if this is a bug, though...

marcus-at-localhost avatar Jan 08 '20 13:01 marcus-at-localhost

Anyway Thank you.

contona68 avatar Jan 08 '20 13:01 contona68

Hi there! It's been a while, but do you guys have found a way to solve this ? I'm facing the same issue. I'm unable find any way to counter this inheriting behaviour.

Also, it doesn't seem that editForm has any effect on custom fields (based on another field) when referring the the lastName component/key for example.

I would really like to find a solution to that, but no docs and no examples found about this so far. I'm not really sure how to deal with it, any hint would be welcome!

DanDvoracek avatar May 11 '21 14:05 DanDvoracek

Closing as this is stale, please feel free to reopen and thank you for everyone's contributions to this discussion.

heather-formio avatar Sep 29 '22 16:09 heather-formio