Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'split' of undefined when adding conditions to radio buttons #1

Closed
sussexrick opened this issue Sep 6, 2018 · 6 comments
Assignees
Milestone

Comments

@sussexrick
Copy link

First logged as http://issues.umbraco.org/issue/CON-1463

Steps to reproduce

Using Umbraco 7.6.12 or 7.7.6, and Forms 6.0.5. Also reported in Forms 7.0.2 by Stefan van Leusden.

Create a form with a "Single choice" field with options of "Yes" and "No", followed by a "Short answer" field. Add a condition to the "Short answer" field so that it only shows when the "Single choice" field is set to "Yes".

Expected result

The short answer field is hidden until "Yes" is selected for the "Single choice" question.

Actual result

The rule is applied correctly, but there is an error in the Chrome console:

 Uncaught TypeError: Cannot read property 'split' of undefined
    at Is (umbracoforms-conditions.js:64)
    at evaluateRuleInstance (umbracoforms-conditions.js:127)
    at evaluateRule (umbracoforms-conditions.js:139)
    at evaluateCondition (umbracoforms-conditions.js:188)
    at evaluateConditionVisibility (umbracoforms-conditions.js:207)
    at isVisible (umbracoforms-conditions.js:215)
    at handleCondition (umbracoforms-conditions.js:221)
    at Object._this.run (umbracoforms-conditions.js:234)
    at Object._this.watch (umbracoforms-conditions.js:110)
    at (index):156

Comment by Patrick Monslaup:

The function that crashes checks if "value" is the same as "expected", and gets a nullpointer on line 64 if the value is null/undefined but expected is not.

At this point you know that the values can't be equal, so add an if sentence before to check if value is undefined but expected is not.

if (value === undefined && expected !== undefined) 
{                
     return false;            
}

This makes the method into..

Is: function(value, expected) {
            if ((value \|\| "") === expected) {
                return true;           
            }            
            if (value === undefined && expected !== undefined) {
                return false;           
            } 
            var values = value.split(',');            
            var matchingExpected = $.grep(values,                
                     function(o) {                    
                                    return o === expected;      
                    });            
            return matchingExpected.length > 0;        
}
@bergmania
Copy link
Member

Duplicate of #24

@warrenbuckley
Copy link

All tested & good :)

@ghost ghost removed the state/review label Nov 14, 2018
@clausjensen clausjensen added this to the sprint98 milestone Nov 15, 2018
@presencewebdesign
Copy link

What the hell! So we spent £180 on this and we have to fix the Javascript issues. I am using Umbraco version 7.10.4,

@tonygayter
Copy link

Any idea when this will be released in Forms 7.0.5? The code above is not in the js on this version and Im not sure where it should go?

@obmnbg
Copy link

obmnbg commented Aug 29, 2019

So how's it going to be? Any ideas about the bugfix and when it will come? Right now manually fixing it and hoping next update doesn't overwrite it doesn't really seem to help...

@attckdog
Copy link

attckdog commented Dec 9, 2020

In the suggested fix for this, What does this code do?
if ((value \|\| "") === expected) { return true; }
I'm trying to implement the fix myself but I'm getting unexpected token. I'd rewrite it but I have no idea what it's really doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants