Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QOL-8650 improve createFormOptions and createFormController #18

Conversation

devonpis
Copy link
Contributor

  • improve flexibility to customise options and controller in createForm function
  • expose options and controller with createFormOptions and createFormController props in initFormioInstance
  • pass createFormOptions and createFormController by data-attribute of the container div

now user can either define indivdual hook function or a global hook function to customise options and controller in any form instances, thus solve the problem of overlapping hook functions in #16 (comment)

@devonpis devonpis requested a review from a team April 11, 2022 03:56
@@ -183,6 +195,8 @@ const initFormio = () => {
formConfirmation: formioFormConfirmation,
formRevision: formioFormRevision,
namespace: formioNamespace,
createFormOptions: window[formioCreateformOptions],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So let's say this is a text field in the squiz metadata.
Would you attach a custom script to the header with the same function name so its available on the window.

On javascript init:
Are you able to pass it as a pointer to a function OR a string that is looked up form window?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in squiz, i would NOT surface createFormOptions as a metadata, instead i'll assign a static function name to createFormOptions , ie.

<div id="formio-%asset_assetid%" class="formio_container" 
    data-formio
    data-formio-project-name="%asset_metadata_project-name%"
    data-formio-form-name="%asset_metadata_form-name%"
    data-formio-form-confirmation="%asset_metadata_form-confirmation%"
    data-formio-form-revision="%asset_metadata_form-revision%"
    data-formio-env-url="%begin_asset_metadata_env-url^eq:test%qol-formio-t-api.azurefd.net%else_begin_asset_metadata_env-url^eq:prod%api.forms.platforms.qld.gov.au%else_asset%%asset_metadata_env-url%%end_asset%"
    data-formio-pdf-download="%asset_metadata_pdf-download%"
    data-formio-namespace="%asset_metadata_namespace%"
    data-formio-createForm-options="formioCreateFormOptions"
    data-formio-createForm-controller="formioCreateFormController"
>
<script src="/?a=123456" type="text/javascript"></script>

and then put window.formioCreateFormOptions in a squiz asset JS file for anyone in squiz to do the customisation
ie. asset #123456

window.formioCreateFormController = ({ envUrl, projectName, formName, form }) => {
  if (projectName === "project2" && formName === "form2") {
    form.on("change", (e) => {
      console.info("onChange", e);
    });
  }
};
window.formioCreateFormOptions = ({ envUrl, projectName, formName }) => {
  if ({ envUrl === "api.forms.platforms.qld.gov.au") {
    return {
      readOnly: true,
    };
  }
  if (projectName === "project1") {
    return {
      readOnly: true,
    };
  }
  if (projectName === "project2" && formName === "form2") {
    return {
      readOnly: true,
    };
  }
  return {};
};

by this way the squiz developers will customise the option and controller in a centralise place/file similar to what they currrently do.

but for non-squiz application, the user have the freedom to define individual or global createFormOptions/Controller.

for the second question, on FormioLoader.formioInit(), currently data-formio-createForm-controller is passed as a string that is looked up form the window object

Copy link
Member

@duttonw duttonw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, have added a comment about how this is wrapped for cms wysiwyg widget as well as direct javascript init (via ref or string name for controller or option variable)

@devonpis devonpis merged commit 5810cb3 into QOL-8650-final-touch-of-the-formio-squiz-improvement Apr 11, 2022
devonpis added a commit that referenced this pull request Apr 11, 2022
* add webhooks and update readme

* improve createFormOptions and createFormController (#18)
@duttonw duttonw deleted the QOL-8650-final-touch-part2 branch April 14, 2022 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants