Hi All,
Is there any configuration available in content fragment component to validate content fragment field, such as if user is not selecting content fragment from available fragments in drop down and clicking on done button, he/she will get notification text( ie: fragment not selected)?
Currently OOB CF component allows user to submit the component on folder only selection.
Solved! Go to Solution.
Views
Replies
Total Likes
@NitinL ,
Here are some videos you can refer:
https://www.youtube.com/watch?v=wFYU1WCkRI0
https://www.youtube.com/watch?v=ouYuFeQjaV8
Here is documentation :
https://stackoverflow.com/questions/30193659/how-add-mandatory-dropdown-field-in-touch-ui
http://experience-aem.blogspot.com/2015/02/aem-6-sp2-touch-ui-dialog-before-submit.html
Please let me know if you know need any inputs.
Thanks,
Aruna
@NitinL ,
I don't think any such feature is available in current CF component. While browsing/selecting the CF from the list it is pointing to CF location so that Content Editor can choose from the list.
if you want to implement anything extra then you have to customize it. My advice is to train authors to choose the CF from the desired location.
Yo can implement the JS to validate the path that is entered by the editor and if it is not CF path then do not allow author to submit the dialog.
Thanks,
Aruna
@NitinL ,
Here are some videos you can refer:
https://www.youtube.com/watch?v=wFYU1WCkRI0
https://www.youtube.com/watch?v=ouYuFeQjaV8
Here is documentation :
https://stackoverflow.com/questions/30193659/how-add-mandatory-dropdown-field-in-touch-ui
http://experience-aem.blogspot.com/2015/02/aem-6-sp2-touch-ui-dialog-before-submit.html
Please let me know if you know need any inputs.
Thanks,
Aruna
Follow the below steps:
1. Overlay the contentfragment dialog from libs to apps. You can find the core component in this path: /libs/core/wcm/components/contentfragment/v1/contentfragment/cq:dialog/
2. Add a property "required" "Boolean" "true" to the fragmentPath field(/libs/core/wcm/components/contentfragment/v1/contentfragment/cq:dialog/content/items/tabs/items/properties/items/column/items/fragmentPath).
required Boolean true
Sorry, I misunderstood the question. In this case you will have to go with a custom validation script. This might take more effort than sounds. I think, you will have to check the resourceType from backend code and use jquery to fetch that and validate.
no worries, can you please share any reference implementation please.. example etc..
Hi @NitinL ,
PFB MVP solution for this.
//validaton property.
//script to validate the CF path
$(window).adaptTo("foundation-registry").register("foundation.validation.validator", { selector: "[data-foundation-validation='fragmentpath.validation']", validate: function(el) { var fragmentPath = el.value; var message = ""; $.ajax({ url: "/bin/validateFragmentPath.json?fragmentPath="+fragmentPath, async: false, success: function(data) { if(!data.hasOwnProperty('success')){ message = "Invalid content path"; } } }); return message; } });
Servlet call to check if its a valid CF,
import java.io.IOException; import javax.servlet.Servlet; import javax.servlet.ServletException; import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.servlets.SlingSafeMethodsServlet; import org.apache.sling.servlets.annotations.SlingServletPaths; import org.osgi.service.component.annotations.Component; import com.adobe.cq.dam.cfm.ContentFragment; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @Component(service = {Servlet.class}) @SlingServletPaths(value="/bin/validateFragmentPath.json") public class CFValidationServlet extends SlingSafeMethodsServlet { private static final long serialVersionUID = 1L; @Override protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); String fragmentPath = request.getParameter("fragmentPath"); ObjectMapper mapper = new ObjectMapper(); ObjectNode keyNode = mapper.createObjectNode(); if(StringUtils.isNotEmpty(fragmentPath)) { ResourceResolver resolver = request.getResourceResolver(); Resource resource = resolver.getResource(fragmentPath); if(resource != null) { ContentFragment fragment = resource.adaptTo(ContentFragment.class); if(fragment != null) { keyNode.put("success", "valid content fragment"); } } } response.getWriter().print(keyNode.toPrettyString()); } }
is there any property so we can verify that our content fragment is saved not publish as i have to require the value when we save the content fragment
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies