We have multiple SHS fields on a form as entityreference widgets. All fields are single-select and not required. This form is embedded into a page and submitted via AJAX.
If any of the fields are left unselected, meaning the user has not chosen a value and left it as '- None -', then the form is submitted, when it is rebuild via the AJAX callback, any unselected fields are missing from form, while fields where the user has selected a term are rebuilt correctly.
I traced the issue back to the parent terms not being set when the unselected items are rebuilt. The Drupal.settings.shs settings show an empty parents array for those fields. This is due to the default_value being set to '_none' instead of NULL when the data is being rebuilt.
I've attached a patch that takes this second scenario into account when rebuilding the form fields so the dummy parent is set to TID 0 and the selector fields are build out by the JS.
Comment | File | Size | Author |
---|---|---|---|
#3 | errormessage.jpg | 99.21 KB | justluvgod |
#1 | shs-missing_fields_ajax_rebuild_revision_1.patch | 598 bytes | abrlam |
shs-missing_fields_ajax_rebuild.patch | 616 bytes | KeyboardCowboy |
Comments
Comment #1
abrlam CreditAttribution: abrlam commentedKeyboardCowboy is on the right track but the problem still persists. Upon examination, seems like the default_value in $form_state is not picking up the empty value correctly (_none option hides SHS field when the form doesn't pass validation). Attached is a patch that rectifies the problem
Could someone or the maintainer review what we have submitted?
Comment #2
dpavon CreditAttribution: dpavon commentedFor the record, I had some problems with these fields when form validations fail (because of other unrelated fields) and their values were "None". The page would reload with selects disabled, except for the ones with a normal value, and user could not choose anything at all.
Patch at #1 works for me, thanks!
Comment #3
justluvgod CreditAttribution: justluvgod commentedI am not sure if this is the same or similar issue. The default value field does not display in my content type. Here is an image. Any idea what could be causing this?
Comment #4
abrlam CreditAttribution: abrlam commentedThat happens when there's no term in the vocabulary. Could you add at least one term and try again?
Sounds like a new issue (minor usability issue).
Comment #5
justluvgod CreditAttribution: justluvgod commentedI ensure there was a associated vocabulary term. I got this to work by deleting the taxonomy terms and reentering again. In addition, I also removed the High-performance JavaScript callback handler.
Thanks for getting me on track.
Comment #6
zoraxI have same problem after installing "High-performance JavaScript callback handler"
the field disappears in the form node and in views....
my taxonomy has terms
Apache/2.4.12
I have put this in htaccess like readme tell
Comment #7
malc0mn CreditAttribution: malc0mn commentedI had something similar as dpavon in #2 (validation problems when nothing was selected). The patch in #1 seems to have solved this issue...
Comment #8
malc0mn CreditAttribution: malc0mn commentedHmmmno, problem is back... I'm going to create a separate issue for this.
k.