The form_builder interface allows to add new fields by just clicking on the link in the palette. While this works fine for non-unique fields it fails for unique fields. The placeholder is never replaced with the actual field although the ajax request is successful.

The problem is that Drupal.formBuilder.addField relies on response.elementId to have the ID of the placeholder element. For unique fields the placeholder gets an ID like new_timestamp while response.elementId contains the name of the field.

I'm unsure what should happen with the element_ids. There is:

  • The id of the placeholder.
  • The id that is passed as $_GET['element_id'].
  • The id thats in response.elementId
  • The id of the actual html output in response.html

How should they fit together?

Comments

torotil’s picture

Here is a workaround that makes the addElement replace the placeholder successfully.

torotil’s picture

StatusFileSize
new2.79 KB

After a few more days of debugging I've come up with a more comprehensive solution. This one get's the element name right in the first place. I've also put the code to generate element names (previously only in dropElement) in newFieldName so that it can be used more generically.

This also fixes issues with adding an element by clicking on it in the palette when the form is empty.

torotil’s picture

Status: Active » Needs review
katzmo’s picture

Thanks for the patch!

I just noticed one little detail that throws a js-error in most browser and makes the form builder unusable:

Drupal.formBuilder.newFieldName = function($element = null) {...}

Default values for parameters in js aren't standard yet and are at the moment only supported by Firefox (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/defaul...).

I'd propose to change the line to

Drupal.formBuilder.newFieldName = function($element) {...}

since the if-condition in the following line checks for $element anyway.

  • torotil committed 7c8f4c3 on 7.x-1.x
    Issue #2278247 by torotil, katomat: Fix handling of unique fields.
    
torotil’s picture

Status: Needs review » Fixed

I've just pushed the patch to 7.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.