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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

abrlam’s picture

KeyboardCowboy 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?

dpavon’s picture

For 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!

justluvgod’s picture

FileSize
99.21 KB

I 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?

abrlam’s picture

That 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).

justluvgod’s picture

I 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.

zorax’s picture

I 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

# Rewrite JavaScript callback URLs of the form js.php?q=x.
RewriteCond %{REQUEST_URI} ^\/([a-z]{2}\/)?js\/.*
RewriteRule ^(.*)$ js.php?q=$1 [L,QSA]
RewriteCond %{QUERY_STRING} (^|&)q=((\/)?[a-z]{2})?(\/)?js\/.*
RewriteRule .* js.php [L]
malc0mn’s picture

I had something similar as dpavon in #2 (validation problems when nothing was selected). The patch in #1 seems to have solved this issue...

malc0mn’s picture

Hmmmno, problem is back... I'm going to create a separate issue for this.

k.