2

I am trying to reuse the Form into my project components. I have copy pasted the entire form folder from "/libs/foundation/components/form" to my project "/apps/mywebsite/components/form". But when i am trying to use the form from mywebsite in the parsys the from shows only Start of the from. Where as when i tried to use the form from the foundation in the same page parsys it shows both Start and End of the form. Observation: From the content, when i am using the foundation form the in the page content i can see the start and end nodes. where as when i am using the mywebsite form start node alone is created.StartEndNodesStartNode

VAr
  • 2,551
  • 1
  • 27
  • 40

1 Answers1

3

The form end is added/deleted by the fixStructure() method of the FormParagraphPostProcessor class. This post processor listens for creation and deletion of form start and form end paragraph and creates/removes the other paragraphs accordingly.

if ( ResourceUtil.isA(res, FormsConstants.RT_FORM_BEGIN)
    || ResourceUtil.isA(res, FormsConstants.RT_FORM_END)) {
    if ( FormsHelper.checkFormStructure(res) != null ) {
        logger.debug("Fixed forms structure at {}", contentResource.getPath());
    }
}else {
    fixStructure(res);
}

This class depends on the FormConstants.java where the form start(RT_FORM_BEGIN) and the form end(RT_FORM_END) are defined as "foundation/components/form/start" and "foundation/components/form/end" respectively. Due to this the post processor doesn't process the form start / end that is present within your project.

To make your custom form component working you may consider one of the following possible options:

  1. Add the sling:resourceSuperType property for your project form start as "foundation/components/form/start". This would create a form end, but it would be of type foundation/components/form/end and not your project form end.

  2. In case you do not want the default form end but your custom form end, then you may need to create a custom post processor which listens to your form start and end and fix the structure accordingly. This requires modifying few other java classes like FormsHelper.java etc, as they are also dependent on the FormConstants.java. Also make sure that the imports in the start.jsp are changed accordingly.

  3. Finally, if you do not want to create custom classes, you can copy the default form start to "/apps/foundation/components/form/start" and make your modifications on top of it. But you need to be careful while using this approach as this is a global change and would affect the other projects that are using the default foundation form start.

rakhi4110
  • 9,253
  • 2
  • 30
  • 49