Skip to content

Commit 5092694

Browse files
authored
FORMS-17046 Focus on panel with static text not working via custom function (#1464)
* Focus on panel with static text not working via custom function * Fixing test
1 parent d0c158a commit 5092694

File tree

5 files changed

+181
-1
lines changed
  • it/content/src/main/content/jcr_root/content
    • dam/formsanddocuments/core-components-it/samples/wizard/setfocus
    • forms/af/core-components-it/samples/wizard/setfocus
  • ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/text/v1/text/clientlibs/site/js
  • ui.frontend/src/view
  • ui.tests/test-module/specs/wizard

5 files changed

+181
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:dam="http://www.day.com/dam/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:fd="http://www.adobe.com/aemfd/fd/1.0"
3+
jcr:primaryType="dam:Asset">
4+
<jcr:content
5+
jcr:lastModified="{Date}2024-10-24T14:51:48.225+05:30"
6+
jcr:primaryType="dam:AssetContent"
7+
sling:resourceType="fd/fm/af/render"
8+
guide="1"
9+
type="guide">
10+
<metadata
11+
fd:version="2.1"
12+
jcr:primaryType="nt:unstructured"
13+
allowedRenderFormat="HTML"
14+
author="admin"
15+
availableInMobileApp="{Boolean}false"
16+
dorTemplateChanged="Boolean"
17+
dorType="none"
18+
formmodel="none"
19+
hasCustomThumbnail="{Boolean}false"
20+
themeRef="/libs/fd/af/themes/canvas"
21+
title="Set focus"/>
22+
</jcr:content>
23+
</jcr:root>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:fd="http://www.adobe.com/aemfd/fd/1.0"
3+
jcr:primaryType="cq:Page">
4+
<jcr:content
5+
cq:deviceGroups="[mobile/groups/responsive]"
6+
cq:lastModified="{Date}2024-10-24T14:51:48.226+05:30"
7+
cq:lastModifiedBy="admin"
8+
cq:template="/conf/core-components-examples/settings/wcm/templates/af-blank-v2"
9+
jcr:language="en"
10+
jcr:primaryType="cq:PageContent"
11+
jcr:title="set focus"
12+
sling:configRef="/conf/forms/core-components-it/samples/wizard/basic/"
13+
sling:resourceType="forms-components-examples/components/page">
14+
<guideContainer
15+
fd:version="2.1"
16+
jcr:primaryType="nt:unstructured"
17+
sling:resourceType="forms-components-examples/components/form/container"
18+
dorType="none"
19+
fieldType="form"
20+
schemaType="none">
21+
<wizard
22+
jcr:lastModified="{Date}2024-10-24T12:46:18.053+05:30"
23+
jcr:lastModifiedBy="admin"
24+
jcr:primaryType="nt:unstructured"
25+
jcr:title="Wizard"
26+
sling:resourceType="forms-components-examples/components/form/wizard"
27+
assistPriority="name"
28+
enabled="{Boolean}true"
29+
fieldType="panel"
30+
hideTitle="false"
31+
id="tooltip_scenario_test"
32+
maxOccur="4"
33+
minOccur="0"
34+
name="wizard1662449848339"
35+
readOnly="{Boolean}false"
36+
repeatable="false"
37+
textIsRich="[true,true]"
38+
visible="{Boolean}true"
39+
wrapData="{Boolean}false">
40+
<item_1729753688746
41+
cq:panelTitle="w1"
42+
jcr:primaryType="nt:unstructured"
43+
jcr:title="Panel"
44+
sling:resourceType="forms-components-examples/components/form/panelcontainer"
45+
fieldType="panel"
46+
name="item_17297536887461729753700324">
47+
<text
48+
jcr:created="{Date}2024-10-24T12:38:29.844+05:30"
49+
jcr:createdBy="admin"
50+
jcr:lastModified="{Date}2024-10-24T12:38:36.331+05:30"
51+
jcr:lastModifiedBy="admin"
52+
jcr:primaryType="nt:unstructured"
53+
jcr:title="Text"
54+
sling:resourceType="forms-components-examples/components/form/text"
55+
fieldType="plain-text"
56+
name="text1729753709875"
57+
textIsRich="true"
58+
value="&lt;p>p1 temp&lt;/p>&#xd;&#xa;"/>
59+
</item_1729753688746>
60+
<item_1729753697276
61+
cq:panelTitle="w2"
62+
jcr:primaryType="nt:unstructured"
63+
jcr:title="Panel"
64+
sling:resourceType="forms-components-examples/components/form/panelcontainer"
65+
fieldType="panel"
66+
name="item_17297536972761729753700328">
67+
<text
68+
jcr:created="{Date}2024-10-24T12:39:02.296+05:30"
69+
jcr:createdBy="admin"
70+
jcr:lastModified="{Date}2024-10-24T12:39:09.217+05:30"
71+
jcr:lastModifiedBy="admin"
72+
jcr:primaryType="nt:unstructured"
73+
jcr:title="Text"
74+
sling:resourceType="forms-components-examples/components/form/text"
75+
fieldType="plain-text"
76+
name="text1729753742328"
77+
textIsRich="true"
78+
value="&lt;p>p2 text&lt;/p>&#xd;&#xa;"/>
79+
</item_1729753697276>
80+
</wizard>
81+
<button
82+
jcr:created="{Date}2024-10-24T14:05:13.949+05:30"
83+
jcr:createdBy="admin"
84+
jcr:lastModified="{Date}2024-10-24T14:05:13.949+05:30"
85+
jcr:lastModifiedBy="admin"
86+
jcr:primaryType="nt:unstructured"
87+
jcr:title="Button"
88+
sling:resourceType="forms-components-examples/components/form/button"
89+
dorExclusion="true"
90+
fieldType="button"
91+
name="button1729758913977">
92+
<fd:rules
93+
fd:click="[{&quot;nodeName&quot;:&quot;ROOT&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;STATEMENT&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;EVENT_SCRIPTS&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;EVENT_CONDITION&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;EVENT_AND_COMPARISON&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;COMPONENT&quot;\,&quot;value&quot;:{&quot;id&quot;:&quot;$form.button1729758913977&quot;\,&quot;type&quot;:&quot;BUTTON&quot;\,&quot;name&quot;:&quot;button1729758913977&quot;}}\,{&quot;nodeName&quot;:&quot;EVENT_AND_COMPARISON_OPERATOR&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;is clicked&quot;\,&quot;value&quot;:null}}\,{&quot;nodeName&quot;:&quot;PRIMITIVE_EXPRESSION&quot;\,&quot;choice&quot;:null}]}\,&quot;nested&quot;:false}\,{&quot;nodeName&quot;:&quot;Then&quot;\,&quot;value&quot;:null}\,{&quot;nodeName&quot;:&quot;BLOCK_STATEMENTS&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;BLOCK_STATEMENT&quot;\,&quot;choice&quot;:{&quot;nodeName&quot;:&quot;SET_FOCUS&quot;\,&quot;items&quot;:[{&quot;nodeName&quot;:&quot;to&quot;\,&quot;value&quot;:null}\,{&quot;nodeName&quot;:&quot;AFCOMPONENT&quot;\,&quot;value&quot;:{&quot;id&quot;:&quot;$form.wizard1662449848339.item_17297536972761729753700328&quot;\,&quot;displayName&quot;:&quot;Panel&quot;\,&quot;type&quot;:&quot;AFCOMPONENT&quot;\,&quot;isDuplicate&quot;:true\,&quot;displayPath&quot;:&quot;FORM/Wizard/Panel/&quot;\,&quot;name&quot;:&quot;item_17297536972761729753700328&quot;\,&quot;parent&quot;:&quot;$form.wizard1662449848339&quot;}}]}}]}]}}]\,&quot;isValid&quot;:true\,&quot;enabled&quot;:true\,&quot;version&quot;:1\,&quot;script&quot;:[&quot;setFocus($form.wizard1662449848339.item_17297536972761729753700328)&quot;]\,&quot;eventName&quot;:&quot;Click&quot;\,&quot;ruleType&quot;:&quot;&quot;\,&quot;description&quot;:&quot;&quot;}]"
94+
jcr:primaryType="nt:unstructured"
95+
validationStatus="valid"/>
96+
<fd:events
97+
jcr:primaryType="nt:unstructured"
98+
click="[setFocus($form.wizard1662449848339\, 'nextItem')]"/>
99+
</button>
100+
</guideContainer>
101+
</jcr:content>
102+
</jcr:root>

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/text/v1/text/clientlibs/site/js/textview.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
}
6060

6161
setFocus() {
62+
const fieldType = this.parentView?.getModel()?.fieldType;
63+
if (fieldType !== 'form' && this.parentView.setFocus) {
64+
this.parentView.setFocus(this.getId());
65+
}
6266
this.setActive();
6367
this.element.scrollIntoView({ behavior: 'smooth', block: 'start' });
6468
}

ui.frontend/src/view/FormField.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class FormField {
7777
setActive() {
7878
if (!this.isActive()) {
7979
this.element.setAttribute(Constants.DATA_ATTRIBUTE_ACTIVE, true);
80-
if (this.parentView) {
80+
// optimizing the performance to check if the activeChild is different, else this will be a redundant call
81+
if (this.parentView?._model?.activeChild !== this._model) {
8182
this.parentView._model.activeChild = this._model; // updating the activeChild of the model when a field is focused in view
8283
}
8384
this.active = true;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*******************************************************************************
2+
* Copyright 2024 Adobe
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
******************************************************************************/
16+
describe("wizard with static text", () => {
17+
18+
const pagePath = "content/forms/af/core-components-it/samples/wizard/setfocus.html";
19+
let formContainer = null
20+
21+
// enabling theme for this test case as without theme there is a bug in custom widget css
22+
before(() => {
23+
const fmPropertiesUI = "/libs/fd/fm/gui/content/forms/formmetadataeditor.html/content/dam/formsanddocuments/core-components-it/samples/wizard/setfocus"
24+
const themeRef = 'input[name="./jcr:content/metadata/themeRef"]'
25+
const propertiesSaveBtn = '#shell-propertiespage-doneactivator'
26+
cy.openPage(fmPropertiesUI).then(() => {
27+
cy.get(themeRef).should('be.visible').clear().type('/libs/fd/af/themes/canvas').then(() => {
28+
cy.get(propertiesSaveBtn).click();
29+
})
30+
})
31+
})
32+
33+
beforeEach(() => {
34+
cy.previewForm(pagePath).then(p => {
35+
formContainer = p;
36+
})
37+
});
38+
39+
it("should focus in the panel if text is first item", () => {
40+
const textComponentId = formContainer._model.items[0].items[1].items[0].id ;
41+
const buttonId = formContainer._model.items[1].id ;
42+
// todo: need to click twice, since today we don't focus on any item on load of the form
43+
// todo: this needs to be still implemented in the form
44+
cy.get(`#${buttonId} button`).click({force: true});
45+
cy.get(`#${buttonId} button`).click({force: true});
46+
cy.get(`#${textComponentId}`).should('be.visible');
47+
})
48+
49+
50+
})

0 commit comments

Comments
 (0)