Hi,

The ability to have conditional form #states was created in 7.14. See: http://drupal.org/node/1464758

When I use this functionality with jQuery Update I get a js error in the Google Chrome console:

Uncaught TypeError: Object 0 has no method 'charAt'

This is an example of code which causes the problem:

$form['example'] = array(
  '#type' => 'textarea',
  '#title' => 'Example Element',
  '#states' => array(
    'visible' => array(
      ':input[name="a_selector_element"]' => array(array('value' => '4'), array('value' => '5'))
    )
  )
);  

I hope this bug report helps. If you need any more information let me know.

Cheers,

Ben

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gamelodge’s picture

I don't get that error but my states do not work when I use 1.7, but if I change back to 1.5 it works.

funature’s picture

me too

gamelodge’s picture

Simply disabling the call to the local version of states worked for me.
jquery_update.module lines 96-98

wrd’s picture

Commenting out lines 96-98 works for me, as well -- no idea yet if there are any side effects of this change.

wrd’s picture

OK, found a side effect. With lines 96-98 commented out, the behavior of the URL Alias fields in the node edit form gets screwed up. When Automatic Alias is unchecked, the field for entering a manual alias is disabled.

wrd’s picture

This has provided a certain measure of relief. I created a custom module using the code here:

http://drupal.stackexchange.com/questions/29576/how-can-i-disable-jquery...

This uses my selected update version of jQuery for non-admin pages, while using 1.5 for admin pages, preventing problems with states as long as the form appears on an admin page. It has a strange side effect of always displaying 1.5 as the selected version in the jQuery Update config form, but it does seem to work otherwise.

SocialNicheGuru’s picture

this might help others. it helped me
http://drupal.org/node/1448490

cbrasfield’s picture

I encountered this error on the latest dev of jquery_update. states.js line 294 had:
while (this.name.charAt(0) == '!') {

I simply changed it to:
while (this.name.toString().charAt(0) == '!') {

Alex Bukach’s picture

Yes, this removes the error, but states still do not work.

MauMau’s picture

Use http://drupal.org/project/jqmulti instead of Jquery Update.
Then core will be able to run on and old jquery alongside your new code running on a newrer version of jquery.

ericduran’s picture

Status: Active » Closed (cannot reproduce)

This is actually fixed in the latest dev version. It has been fixed for a while. jquery_update replaces the actual drupal states.js file.

jqmulti is great, but I don't like having multiple jquery version :) I rather just fix the core issues. That being said if it works for other people please feel free to use it.

This is fixed, please test the latest dev version.

muschpusch’s picture

Status: Closed (cannot reproduce) » Active

@ericduran: sorry to reopen but i needed to apply the fix from #8 and i use latest dev :/

[edit] just be sure i checked: http://drupalcode.org/project/jquery_update.git/blob/refs/heads/7.x-2.x:... [/edit]

j0rd’s picture

I noticed this problem today. Updated to latest -dev and it fixed the page which was causing me problems.

@muschpusch what is the page / module which is causing you problems?

For me it was the "administration pages" of editing a "double_field". My problem is resolved.

mattlc’s picture

#13 didn't worked for me.

j0rd’s picture

@mattic, you're input isn't very helpful in moving this issue queue forward.

Any idea what page / module is causing you problems? If you'd like a more complete solution, you're going to have to provide some information.

muschpusch’s picture

i get this on a node edit page. Different fields are on it... I will try reproduce in a simpler environment.

muschpusch’s picture

Status: Active » Fixed

sorry but i just realized that i had an older version of jquery_update in the sites/domain.com directory which was used instead of the more recent version in sites/all. Using the latest version indeed fixed the issue. Setting this to fixed since there was no other reply j0st

Status: Fixed » Closed (fixed)

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

jcmartinez’s picture

Sorry for reopening but this bug is still in 7.x.2x-dev.

It can be reproduced as follows:

  1. Install jQuery Update, version 7.x.2x-dev.
  2. Configure in admin/config/development/jquery_update, Default jQuery Version = 1.8 (same if 1.7). Alternate jQuery version for administrative pages = Use default. Compression level = Uncompressed.
  3. Install Conditional Fields, version 7.x-3.x-dev.
  4. Create a content type and add fields.
  5. Use the tab added by conditional fields to add states so that a field hide or show depending on the selection of another field.
  6. Provide permission to anonymous to create new content for the new content type.
  7. Become anonymous and try to create a node of the new content type.

You will notice that the conditional field will not fire and chrome will show this error in the console: Uncaught TypeError: Object 0 has no method 'charAt'.

Commenting out the following code will partially solve the problem:

// Replace files for jQuery 1.7 and up
  if (version_compare($version, '1.7', '>=')) {
   $javascript['drupal.states']['js']['misc/states.js']['data'] = $path . '/replace/misc/1.7/states.js';
  }

After deleting or commenting out the code above, a new error will show in Chrome's console: Uncaught TypeError: Cannot read property 'length' of undefined

Hope this helps tracking the issue.

Thank you for this great module!

jcmartinez’s picture

Status: Closed (fixed) » Active
hefox’s picture

Anonymous’s picture

Still having same problem with latest dev. My scenario is essentially identical to jmartinez's.

Tokoh’s picture

Hi I tried like jmartinez and got the same problem then I tried using 1.5 instead of default for admin pages and it worked.

VVS’s picture

Hi I tried like jmartinez and got the same problem then I tried using 1.5 instead of default for admin pages and it worked.

Hi. Yes 2.x-dev for admin pages (/admin/structure/dependencies/edit/) this is working. But not for node/add & node/*/edit pages. I used a module Conditional fields. To comment of:

  if (version_compare($version, '1.7', '>=')) {
   $javascript['drupal.states']['js']['misc/states.js']['data'] = $path . '/replace/misc/1.7/states.js';
  }

is working for conditional fields.

hefox’s picture

Status: Active » Postponed

Just to reiterate, there's a patch for the issue in #1448490: Remove the states.js overwrite as it was fixed upstream, which fixes this issue, so review it/bump that issue?

botris’s picture

Status: Postponed » Closed (fixed)

Upgrading to dev fixes the problem, can't tell if it's due to #1448490

heshanlk’s picture

Upgrading to the Dev version fixed the issue.

danharper’s picture

I am using dev and getting problems with the following form only when using anything other than jquery 1.5

      '#states' => array(
        'visible' => array(
          ':input[name="type"]' => array(
            array('value' => 'now'),
            array('value' => 'then'),
          )
        ),
      ),

Although there is no js error in the console the desired behaviour is not achieved, the form is displayed regardless of

Calcifer’s picture

I have exactly the same problem.
I'm using the latest dev release (7.x-2.x-dev), but if i use jQuery version different than 1.5, #states doesn't work.
this is an example:

'#states' => array(
              'visible' => array(
                  array(
                      'select[name="octo_sinisters"]' => array('value' => '2'),
                      //),
                      //array(
                      'select[name="octo_car_years_insured"]' => array(
                          array('!value' => ''),
                      ),
                  ),
              ),
              'enabled' => array(
                  array(
                      'select[name="octo_sinisters"]' => array('value' => '2'),
                      'select[name="octo_car_years_insured"]' => array(
                          array('!value' => ''),
                      ),
                  ),
              ),
noels’s picture

I have made a couple of changes to bring conditional_fields in line with newer (>= 1.7) jquery and the states supplied by jquery_update.

In #8, it was suggested that you should just ensure that the name of the state was a string. This will only hide the problem. The root cause of this is that states requires a slightly different format for the states and values. I have amended conditional_fields module to provide the required changes. You do not need either the development version or jquery_update or any other patch to jquery_update for this to work.

Additionally, states now provides a good mechanism for value comparison, so the implementation of compare in conditional_fields.js conflicts with the changes to states.js. I have removed this implementation.

Finally, the jquery api for obtaining event data from an element has been removed. See the 1.8 change log: http://blog.jquery.com/2012/08/09/jquery-1-8-released/ I have modified the call to use the unsupported private interface $._data(document, "events") but this is likely to change and may well break in future jquery releases. It needs a proper solution (unbind existing handlers and bind new ones which call the existing ones), but time did not permit.

noels’s picture

This is not the file you are looking for...

noels’s picture

presleyd’s picture

I had several issues after this patch with jquery 1.7. Regular expression conditional fields did not evaluate at all, several OR conditional fields evaluated erratically as well.
An alternative solution to this problem, and probably the correct one, should this small core patch be accepted: #2018791: states.js is not compatible with jquery +1.6.1 because it use $.attr in the wrong way

See also #1448490: Remove the states.js overwrite as it was fixed upstream

sonniesedge’s picture

I've tried applying the core patch, as linked in #33, but I still see failures when using OR states in FAPI fields with jquery 1.7+. Anybody else got this working?

yeaha’s picture

altering states.js like #8, worked for me (jquery 1.7 gave same error "Object 0 has no method 'charAt'" in search api fields settings)

jcfiala’s picture

This is still not fixed, it seems? I'm using 7.x-2.3, and I"m still getting the "Object 0 has no method 'charAt'" error. Using the 'fix' in #8 has fixed the problem for me as well.

Damien Laguerre’s picture

Status: Closed (fixed) » Active

The problem has not been solved.

I've have the same problem with the last version of April 3, 2014.

#8 Works for me too

markhalliwell’s picture

Status: Active » Closed (fixed)
Related issues: +#1448490: Remove the states.js overwrite as it was fixed upstream
bshensky’s picture

#8 did the trick for us - we have 5-6 dozen dependencies in operation on a single form.

Javascript Error console was barking this on page refresh:

Timestamp: 4/10/2014 2:10:08 PM
Error: TypeError: this.name.charAt is not a function
Source File: http://dev.*****.org/prime/sites/all/modules/jquery_update/replace/misc/1.7/states.js?v=7.26
Line: 294

Adding the toString() made the problem go away.

It appears that the problem is associated with state values that can be interpreted as non-strings, such as "1" or "0" or whatnot. Our use of field_dependencies was fine until we introduced a dependency on a parent field that used such type-bending values.