Skip to main content
brunovianarezen
Level 2
Oct 22, 2015 7:06 PM UTC
Solved

regex bug in dialog with a single textfield, AEM 5.6.1

Hi,

I've just found this bug in my AEM 5.6.1 instance: if a dialog tab has only 1 field and this field is a textfield with a regex property then the author will get the error 'this.regex.test is not a function'. Is this a known bug? if so, what is the recommendation to workaround it?

Bellow I'll put some of the investigation I've done, in case it might help:

I think the culprit is this piece of code (inside function FormatData in file /libs/cq/ui/widgets/source/utils/Util.js):

                            if (i == "items" && array.length == 1) {
                                // set single items directly as object
                                data[i] = array[0];
                            }
                            else {
                                data[i] = array;
                            }

other parts of the system expect data[i] to be an array, even it has only one element. For an example, the function 'CQ.Util.applyDefaults' has this piece of code:

                if (value && typeof value == "object" &&
                        !(value instanceof Array) && !isCqInstance(value)) {

                    base[name] = CQ.utils.Util.applyDefaults(base[name], value);
                }

as can be seen, the conditional will be evaluated to true and CQ.utils.Util.applyDefaults will be wrongly called. This call will in turn change the value of regex from a RegExp instance to an Object instance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
edubey
edubeyAccepted solution
Level 10
Oct 24, 2015 12:42 PM UTC

Hi,

I was able to replicate this, can you please raise a day care ticket for the same.

6 replies

smacdonald2008
Level 10
Oct 22, 2015 9:42 PM UTC

I am going to see if i can reproduce these results. I will post back the findings. 

Translate
brunovianarezen
Level 2
Oct 23, 2015 11:37 AM UTC

smacdonald2008 wrote...

I am going to see if i can reproduce these results. I will post back the findings. 

 


thanks! Some more data:

1. if the dialog has more than one tab, the error doesn't happen

2. if the dialog has a sibling cq:editConfig node, the error doesn't happen

here is a definition of a dialog that triggers the error:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:Dialog" xtype="dialog">
    <items jcr:primaryType="cq:Widget" activeTab="{Long}0" xtype="tabpanel">
        <items jcr:primaryType="cq:WidgetCollection">
            <tab jcr:primaryType="cq:Widget"
                xtype="panel"
                title="test">
                <items jcr:primaryType="cq:WidgetCollection">
                    <test
                       jcr:primaryType="cq:Widget"
                       allowBlank="{Boolean}false"
                       regex="/[a-zA-Z0-9]+/"
                       fieldLabel="Test"
                       name="./test"
                       xtype="textfield" />
                </items>
            </tab>
        </items>
    </items>
</jcr:root>

if you add a new field called 'hack' of type hidden, the error disappears.

Translate
edubey
edubeyAccepted solution
Level 10
Oct 24, 2015 12:42 PM UTC

Hi,

I was able to replicate this, can you please raise a day care ticket for the same.

Translate
brunovianarezen
Level 2
Oct 26, 2015 10:06 AM UTC

ok, I'll.

Translate
Feb 1, 2016 3:00 PM UTC

Hi,

 

I'm having the same issue. Is there a hot-fix available?

Translate
vyan024
Level 2
Aug 29, 2016 1:06 PM UTC

Hi @bru

brunovianarezende wrote...

smacdonald2008 wrote...

I am going to see if i can reproduce these results. I will post back the findings. 

 


thanks! Some more data:

1. if the dialog has more than one tab, the error doesn't happen

2. if the dialog has a sibling cq:editConfig node, the error doesn't happen

here is a definition of a dialog that triggers the error:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:Dialog" xtype="dialog">
    <items jcr:primaryType="cq:Widget" activeTab="{Long}0" xtype="tabpanel">
        <items jcr:primaryType="cq:WidgetCollection">
            <tab jcr:primaryType="cq:Widget"
                xtype="panel"
                title="test">
                <items jcr:primaryType="cq:WidgetCollection">
                    <test
                       jcr:primaryType="cq:Widget"
                       allowBlank="{Boolean}false"
                       regex="/[a-zA-Z0-9]+/"
                       fieldLabel="Test"
                       name="./test"
                       xtype="textfield" />
                </items>
            </tab>
        </items>
    </items>
</jcr:root>

if you add a new field called 'hack' of type hidden, the error disappears.

 

How did you fix this issue? Can you please share the solution?

Translate