Problem/Motivation
If a user creates a form element and updates the key to a non-unique value, the form element key edit box disappears. Further to this, when the element edit is closed, the entire form element disappears and on form save the element is deleted.
Steps to reproduce
You can reproduce this behaviour by doing the following:
- Enable and configure the
webform,form_builderandform_builder_webformmodules - Create a new webform
- Add a new form element, give it the title Element one and edit the key so it reads
non_unique_key - Drag across a second form element, give it the title Element two and edit the key so it reads
non_unique_key - Save the form
Expected behaviour
An error message should appear that tells me that I cannot save the form until I edit the keys to make them unique. The error message should be similar or the same as the message provided in Webform module for this validation condition.
Actual behaviour
After clicking anywhere outside the edit box of the second form element, the element disappears and on save, is deleted. No message is shown indicating why this happens.
Proposed resolution
The same scenario, when done in webform without the form_builder_webform module, returns an error on save that reads:
"The field key %key is already in use by the field labeled %label. Please use a unique key."
The Form Builder Webform UI module should display a similar error message, forcing the user to rename the key before continuing.
Remaining tasks
A simpletest test case should be written to test and reproduce this behaviour.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | form_builder-fixup-duplicate-key-validation-1853628-8.patch | 1.72 KB | torotil |
Comments
Comment #1
thechanceg commentedHas anything been done on this? Your proposed solution sounds perfect.
I notice that this issue is related to the stable release, has this functionality made it dev yet?
Comment #2
amir simantov commentedThis issue might be closed.
In a fresh install of Surveyor I cannot see this problem; in a case of a duplication I do get an error message "The form key new_textfield is already in use".
Got here by searching "duplicate".
Comment #3
markus_petrux commentedStill an issue here.
Would it work a validation callback attached to the form "form_builder_field_configure"?
...looking at the code, it seems that we want to make sure
$form['#_edit_element']['#key']is unique, but where to look for the keys of the other components that are being edited? Any hint on this?Comment #4
torotil commentedI guess a validation handler on form_builder_field_configure might just work. You can get the currently active form (including all other fields) from
form_builder_active_form().Comment #5
markus_petrux commentedIt has not been so obvious to find. I did the best I could...
Comment #6
torotil commentedThat might be a bit too strict. A duplicate key is fine as long as it doesn't have the same parent too. For example:
is a valid form structure.
Comment #7
torotil commentedErm and another thing: I can't reproduce the bug in 7.x-1.x -- also there already is
form_builder_property_key_form_validate()which should take care of this - and does so for me.Comment #8
torotil commentedOk still found a bug with that validation: The current validation only checks for duplicate keys in the "global" form array. That means:
I'm attaching a patch that fixes the validation.
@markus_petrux: could you check whether that fixes your problems too?
Comment #10
torotil commentedOk, I've committed #8.