I am trying to figure out how to refresh a granite data source for a select field from a pathfield that I will like to also pass into the data source.
Basically:
Set a path (pathToOptions) that will look at a content fragment model
Datasource is called, each time the path value has changed in the dialog, to Sling Servlet to retrieve all fields of content fragment
Author dialog generates options, for granite select drop down (cfOptions), with the fields from the data source.
<pathToOptions jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/pathfield" fieldLabel="CF Path" rootPath="/content" name="./pathToOptions"/> <cfOptions jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/select" fieldLabel="CF Options" name="./cfOptions"> <datasource jcr:primaryType="nt:unstructured" sling:resourceType="/bin/path/to/servlet"/> </resProperties>
(Variable names and paths are just generic)
Without so much knowledge of AEM Granite data sources and Apache Sling API; is there a viable method with the data source, or would I need to rely on AJAX. If the latter, i'll post a follow up question.
After some research; it turns out it is not possible to do this with a datasource, but instead use AJAX (
$.ajax()) to communicate with the Sling Servlet to achieve the necessary functionality.https://helpx.adobe.com/experience-manager/using/creating-touchui-dynamic.html
I used this documentation as a base to do the functionality, but adjusted to my specifications.
This snippit is originally from the article. I only applied it just in case if the link goes dead. I've seen plenty of Adobe's forum posts having 404 links, so this is added as a precaution for future reference.