angthefire
angthefire
07-11-2017
I have a set of radio buttons (top, center and bottom). My requirement is such that I have used the property "checked" as true to show "center" as the selected one when the component is dragged and dropped on the page.
If I open the dialog, selects the radio button "top" and click submit, I am getting the value as "top" in my html page. But, if I reopen the dialog, the "center" button is selected instead of "top".
As per requirement, I can't change the order of radio button as well as default selection.
smacdonald2008
smacdonald2008
07-11-2017
If you look at docs - you can set default - Radio — Granite UI 1.0 documentation
Have you tried that?
angthefire
angthefire
07-11-2017
Hi smacdonald2008,
Thanks for the reply.
The issue here is not with setting the default value. Let me try to explain the issue with the help of some snapshots.
The above snapshot shows the selection of "center" radio button (which I achieved via checked(boolean) property).
I selected the "Top" radio button and clicked submit.
Now if I reopen the dialog, I see the following:
I hope the question is more clear than before.
Thanks
smacdonald2008
smacdonald2008
07-11-2017
You see that because it has the prop checked. Therefore each time you open a dialog - the checked property is used, This would be the same for any form that has a radio group and one radio option is set as default. As a result, each time an author opens the dialog and wants another value, they will have to select either Top or Bottom.
edubey
edubey
12-02-2018
Below is the structure which I used and work. You can refer
{
"jcr:primaryType": "nt:unstructured",
"personalyes": {
"jcr:primaryType": "nt:unstructured",
"name": "./myValue",
"text": "Yes",
"value": "yes",
"sling:resourceType": "granite/ui/components/foundation/form/radio"
},
"personalno": {
"jcr:primaryType": "nt:unstructured",
"name": "./myValue",
"text": "No",
"value": "no",
"sling:resourceType": "granite/ui/components/foundation/form/radio"
},
"defaultvalue": {
"jcr:primaryType": "nt:unstructured",
"name": "./myValue@DefaultValue",
"value": "no",
"sling:resourceType": "granite/ui/components/foundation/form/hidden"
},
"defaultwhenmissing": {
"jcr:primaryType": "nt:unstructured",
"name": "./myValue@UseDefaultWhenMissing",
"value": "true",
"sling:resourceType": "granite/ui/components/foundation/form/hidden"
}
}
anelem1760873
anelem1760873
15-05-2018
Hi Guys,
Has anyone find the solution for this, am also facing the same issue.
Thanks
Arun_Patidar
MVP
Arun_Patidar
MVP
15-05-2018
I used coral3 radio granite/ui/components/coral/foundation/form/radiogroup
working for me as expecting without adding extra node/property
anirudh_sharma1
anirudh_sharma1
25-06-2018
As per the documentation - RadioGroup — Granite UI 1.0 documentation, you can try the following -
<testRadioGroup
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/radiogroup"
ignoreData="{Boolean}false"
text="Test Radio"
vertical="{Boolean}true">
<items jcr:primaryType="nt:unstructured">
<option1
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/radio"
checked="{Boolean}true"
name="./testRadio"
text="Option 1"
value="option1"/>
<option2
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/radio"
name="./testRadio"
text="Option 2"
value="option2"/>
</items>
</testRadioGroup>
I tested this on AEM 6.4 and it is working fine for me. The trick has been done by the ignoreData property. Happy coding
Akash_Ramchanda
Akash_Ramchanda
11-07-2018
Hi Anirudh,
Can you set the checked property on the second option and test the same.
We are facing the same issue and looking for a solution for it ASAP.
We are still using 6.2 and I am sure that AEM version has nothing to do with it because the granite version is the same.
kenccwong
Employee
kenccwong
Employee
13-12-2018
It looks like /libs/granite/ui/components/foundation/form/radio/radio.jsp is not following the specification correctly. What it does is first checks if "checked" property is available, if not available then it will check if "ignoreData" is set to false in the parent radio group.
Workaround is to create an overlay and add an additional check to see if a value is set.
if (cfg.get("checked", String.class) != null && val.getContentValue(name) == "") {
// providing "checked" in configuration results in ignoring content data
attrs.addChecked(cfg.get("checked", false));
} else if (!cfg.getInherited("ignoreData", false)) {
// mark checked if content value equals config value
attrs.addChecked(val.getContentValue(name).equals(value));
}