1

I wrote a custom module that adds a widget. This widget consists of multiple textfields and an ajax button that sends that information to an external service and gets in return and identifier that is stored locally.

However, it is not possible to render this widget within a group. (Using the field group module) When adding it to a content type it will never be rendered within a group (as a fieldset, a tab, div or whatever), but instead before or after it.

My custom fields within the widget are bundled together by:

$form['fieldset']['field_name1']
$form['fieldset']['field_name2']

But even when they are not put together as a fieldset, it doesn't work.

How come?

Here is a code snipped of the definition of the fieldset:

$form['b2share_fieldset'] = array(
  '#type'  => 'fieldset',
  '#title'  => t('Publish data on B2Share'),
  '#collapsible'  => TRUE,
  '#collapsed' => FALSE,
  '#tree'  => TRUE,
);

$form['b2share_fieldset']['database_field_name'] = array(
   '#type'  => 'hidden',
   '#default_value'  => $b2share_fieldname,
);

The complete module can be found here.

I want to emphasize that my widget works fine. It's just always displayed outside the fieldgroup even when it is placed within the fieldgroup. Declaring it as a container as described here doesn't work either.

I also tried the patch provided here, but without success.

Also when I remove the fieldgroup and just leave the fields in there, they are always rendered outside the parent element.There aren't any status or error messages either.

I actually want to publish this as a contributed module, so I'd appreciate any help as I want to get rid of this bug, before I do that.

The problem is also described here.

1
  • Could you post the entire code you're using? First of all, did you declare your fieldset as such? $form['fieldset'] = array( '#type' => 'fieldset', '#title' => t('Fieldset'), ); Commented Jan 24, 2017 at 9:20

1 Answer 1

0

OK. I finally found the problem based on the example code here. The problem was that I constantly used "form" instead of element. Once I had replaced that the rendering was correct.

$form['b2share_fieldset']

instead of $element['b2share_fieldset']

However, the huge downside is that now I don't know how to access the field information as $form_state isn't working anymore.

EDIT: After applying some minor changes in the code I can confirm that this approach works. The fully functional code can be seen on github.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.