angular icon indicating copy to clipboard operation
angular copied to clipboard

Change Weight for Custom Form Builder Components?

Open JRiggenbach opened this issue 5 years ago • 2 comments

Hello again, When configuring a custom Form Builder, is there a way to change the weight of the actual components themselves? Not the categories, but the components. For example, I would like to just put a collection of components that are in the basic and advanced grouping under one custom "Components" section, but I would like to be able to group them accordingly.

Given this configuration, I would like to group the date/time related components together: options

But when they are rendered, they end up like this (with checkbox mixed in between) rendered

Thanks in advance.

JRiggenbach avatar Apr 16 '20 03:04 JRiggenbach

You will probably need to also change the "weight" of the other components which is provided in their "builderInfo" method. Something like this may allow you to modify any components builderInfo weight.

var checkBoxInfo = Formio.Components.components.checkbox.builderInfo;
checkBoxInfo.weight = 200;
Object.defineProperty(Formio.Components.components.checkbox, 'builderInfo', {
  get() { 
    return checkBoxInfo;
  }
});

Note: I have not actually tested this to see if it works, but I have a hunch it may.

travist avatar Apr 17 '20 15:04 travist

@travist Thanks for your solution, it totally works for me. One more addition to it to make it little optimized

import {Formio} from 'formiojs';

// Sequence
let index = 500;
[
  'textfield',
  'textarea',
  'email',
  'selectboxes',
  'select',
  'phoneNumber',
  'radio',
  'datetime',
  'button',
].forEach(name => {
  let component = Formio.Components.components[name].builderInfo;
  component.weight = index++;
  Object.defineProperty(Formio.Components.components[name], 'builderInfo', {
    get() {
      return component;
    },
  });
});

alphazhe avatar Jan 25 '22 12:01 alphazhe

We're currently addressing a backlog of GitHub issues, and as part of this effort, some inactive issues may be marked as closed. This isn't a dismissal, but a step toward more efficient tracking.

If you feel the issue is still relevant, please re-open and we'll ensure it gets the attention it deserves. Your understanding is appreciated as we work to enhance our open-source responsiveness.

Sidiro23 avatar Jan 31 '24 14:01 Sidiro23