allowBlank on select in multifield (Touch UI) doesn't work | Community
Skip to main content
Level 2
October 16, 2015
Solved

allowBlank on select in multifield (Touch UI) doesn't work

  • October 16, 2015
  • 12 replies
  • 3577 views

Using the Touch UI interface, I have a 'multifield' that contains a series of 'select' fields.  I can select, change, and delete items in this multifield just fine, however, when I try to remove the last remaining 'select' from the multifield and save, the last item is not removed.  I've tried setting the 'allowBlank' property to true, but it still won't let me remove the last item from the multifield.  Any ideas on how I can achieve this?

UPDATE

Here is the contents of my .content.xml file for the cq:dialog node.  The /jcr:root/content/items/section-filters/items/permissions node is the offender.  I'm not sure that 'allowBlank' is a valid property in the Touch UI:

<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="nt:unstructured" jcr:title="Edit Portal Component" sling:resourceType="cq/gui/components/authoring/dialog"> <content jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/container"> <layout jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/layouts/tabs"/> <items jcr:primaryType="nt:unstructured"> <section-properties jcr:primaryType="nt:unstructured" jcr:title="Properties" sling:resourceType="granite/ui/components/foundation/container"> <items jcr:primaryType="nt:unstructured"> <caption jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/textfield" fieldDescription="A caption for the component" fieldLabel="Caption" name="./caption"/> <applet-size jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/textfield" fieldDescription="1-12 or flush" fieldLabel="Applet Size" name="./applet-size"/> </items> </section-properties> <section-filters jcr:primaryType="nt:unstructured" jcr:title="Portal Filters" sling:resourceType="granite/ui/components/foundation/container"> <items jcr:primaryType="nt:unstructured"> <permissions jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/multifield" fieldDescription="A user must have at least one of these permissions to view this component" fieldLabel="Permissions" name="./permissions"> <field jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/select" allowBlank="{Boolean}true" name="./permissions"> <datasource jcr:primaryType="nt:unstructured" sling:resourceType="/apps/mportal/datasources/permissions"/> </field> </permissions> <startdate jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/datepicker" fieldLabel="Start Date" name="./startdate"/> <enddate jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/form/datepicker" fieldLabel="End Date" name="./enddate"/> </items> </section-filters> </items> </content> </jcr:root>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by harrisonreed

It turns out there is an issue with the way AEM Touch UI multifield components update values. If you remove the last item, the component sends no value up to the server (much like an unchecked checkbox). You have to explicitly tell AEM that you want to delete the value of a multifield if there are no items in it. Here's how:

  1. At the same level as your multifield node, create a new node (nt:unstructured); I call it permissions-delete (to correspond with my multifield called permissions)
  2. Add the following properties:
    1. sling:resourceTypeStringgranite/ui/components/foundation/form/hidden
    2. nameString./permissions@Delete (where ./permissions is the value of name field of the permissions/field node)
    3. valueBoolean, true

Now when you remove the last item, the value of the hidden field will ensure that it is deleted and not just ignored.

12 replies

Community Advisor
October 16, 2015

It could be some thing in your code(multifield) widget or dialog.xml that is causing this issue. I may be able to give some hint if you post snippet of your code.

harrisonreedAuthorAccepted solution
Level 2
October 16, 2015

It turns out there is an issue with the way AEM Touch UI multifield components update values. If you remove the last item, the component sends no value up to the server (much like an unchecked checkbox). You have to explicitly tell AEM that you want to delete the value of a multifield if there are no items in it. Here's how:

  1. At the same level as your multifield node, create a new node (nt:unstructured); I call it permissions-delete (to correspond with my multifield called permissions)
  2. Add the following properties:
    1. sling:resourceTypeStringgranite/ui/components/foundation/form/hidden
    2. nameString./permissions@Delete (where ./permissions is the value of name field of the permissions/field node)
    3. valueBoolean, true

Now when you remove the last item, the value of the hidden field will ensure that it is deleted and not just ignored.

Community Advisor
October 16, 2015

Hi Harrison,

Thank you for finding  a workaround to fix this issue. It works, I verified by  modifying changes to your component.

M. Shaji Ahmed

Level 2
October 16, 2015

I updated the question with the contents of .content.xml for the cq:dialog node.

Community Advisor
October 16, 2015
  1. <permissions
  2. jcr:primaryType="nt:unstructured"
  3. sling:resourceType="granite/ui/components/foundation/form/multifield"
  4. fieldDescription="A user must have at least one of these permissions to view this component"
  5. fieldLabel="Permissions"
  6. name="./permissions">
  7. <field
  8. jcr:primaryType="nt:unstructured"
  9. sling:resourceType="granite/ui/components/foundation/form/select"
  10. allowBlank="{Boolean}true"
  11. name="./permissions">

​You have same names(./permissions) for both the fields permissions and field, can you make the names unique and try again

Level 2
October 16, 2015

I'm afraid that did not fix the problem.  The value persists despite all attempts to the contrary! (Unless, of course, I remove it explicitly through the CRX interface.)

Community Advisor
October 16, 2015

Can you attach package, also which version of AEM r u using?

Level 2
October 16, 2015

I am running AEM 6.0.  Attached is a "base-component", a "test-component" with a sling:resourceSuperType of "base-component", and a tabs folder that contains a dialog tab used in the base-component.  Try adding items to any of the multi-fields, save, then try to remove, save again and reopen the dialog to see if at least one of the items is still there.

Community Advisor
October 16, 2015

It seems that your package has some missing files, it doesn't work for me. I got

Caused by: org.apache.sling.scripting.jsp.jasper.JasperException: /apps/mportal/components/base-component/base-component.jsp(1,1) File "/apps/mportal/global.jsp" not found

Please make sure you have all necessary files before you upload.

Level 2
October 16, 2015

Sorry about that.  I've created a new package and loaded it into a fresh instance of AEM; it seems to work fine now.  Once you have this new package loaded, you can find a test page at localhost:4502/editor.html/content/mportal/test.html  Open the edit dialog for any of the components on that page and click the "Portal Filters" tab.  If you edit the first component on the page (the one that says "Hello People! (Flush)"), then you should see that there is a permission selected.  Attempting to remove this and reopen the dialog should demonstrate the problem.  Note: changing a permission, adding a new permission, or even removing a permission that's not the last item in the multifield saves just fine.  The issue only occurs when attempting to remove the last item in the multifield.

I really appreciate you being willing to help me with this.