Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#32 | conditional_fields-jquery_update_1.7_states_incompatible-1815896.patch | 1.74 KB | noels |
Comments
Comment #1
gamelodge CreditAttribution: gamelodge commentedI 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.
Comment #2
funature CreditAttribution: funature commentedme too
Comment #3
gamelodge CreditAttribution: gamelodge commentedSimply disabling the call to the local version of states worked for me.
jquery_update.module lines 96-98
Comment #4
wrd CreditAttribution: wrd commentedCommenting out lines 96-98 works for me, as well -- no idea yet if there are any side effects of this change.
Comment #5
wrd CreditAttribution: wrd commentedOK, 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.
Comment #6
wrd CreditAttribution: wrd commentedThis 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.
Comment #7
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedthis might help others. it helped me
http://drupal.org/node/1448490
Comment #8
cbrasfield CreditAttribution: cbrasfield commentedI 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) == '!') {
Comment #9
Alex Bukach CreditAttribution: Alex Bukach commentedYes, this removes the error, but states still do not work.
Comment #10
MauMauUse 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.
Comment #11
ericduran CreditAttribution: ericduran commentedThis 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.
Comment #12
muschpusch CreditAttribution: muschpusch commented@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]
Comment #13
j0rd CreditAttribution: j0rd commentedI 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.
Comment #14
mattlc CreditAttribution: mattlc commented#13 didn't worked for me.
Comment #15
j0rd CreditAttribution: j0rd commented@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.
Comment #16
muschpusch CreditAttribution: muschpusch commentedi get this on a node edit page. Different fields are on it... I will try reproduce in a simpler environment.
Comment #17
muschpusch CreditAttribution: muschpusch commentedsorry 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
Comment #19
jcmartinezSorry for reopening but this bug is still in 7.x.2x-dev.
It can be reproduced as follows:
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:
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!
Comment #20
jcmartinezComment #21
hefox CreditAttribution: hefox commentedPatch over at #1448490: Remove the states.js overwrite as it was fixed upstream
Comment #22
Anonymous (not verified) CreditAttribution: Anonymous commentedStill having same problem with latest dev. My scenario is essentially identical to jmartinez's.
Comment #23
Tokoh CreditAttribution: Tokoh commentedHi I tried like jmartinez and got the same problem then I tried using 1.5 instead of default for admin pages and it worked.
Comment #24
VVS CreditAttribution: VVS commentedHi. 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:
is working for conditional fields.
Comment #25
hefox CreditAttribution: hefox commentedJust 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?
Comment #26
botrisUpgrading to dev fixes the problem, can't tell if it's due to #1448490
Comment #27
heshanlkUpgrading to the Dev version fixed the issue.
Comment #28
danharper CreditAttribution: danharper commentedI am using dev and getting problems with the following form only when using anything other than jquery 1.5
Although there is no js error in the console the desired behaviour is not achieved, the form is displayed regardless of
Comment #29
Calcifer CreditAttribution: Calcifer commentedI 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:
Comment #30
noels CreditAttribution: noels commentedI 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.
Comment #31
noels CreditAttribution: noels commentedThis is not the file you are looking for...
Comment #32
noels CreditAttribution: noels commentedComment #33
presleyd CreditAttribution: presleyd commentedI 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
Comment #34
sonniesedge CreditAttribution: sonniesedge commentedI'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?
Comment #35
yeaha CreditAttribution: yeaha commentedaltering states.js like #8, worked for me (jquery 1.7 gave same error "Object 0 has no method 'charAt'" in search api fields settings)
Comment #36
jcfiala CreditAttribution: jcfiala commentedThis 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.
Comment #37
Damien Laguerre CreditAttribution: Damien Laguerre commentedThe problem has not been solved.
I've have the same problem with the last version of April 3, 2014.
#8 Works for me too
Comment #38
markhalliwellComment #39
bshensky CreditAttribution: bshensky commented#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:
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.