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

Release v1.0.4 #21

Merged
merged 3 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<link href="https://www.qld.gov.au/_qgdesigns/css/qg-main.css?v=0.3.0" rel="stylesheet">
<link href="https://www.qld.gov.au/__data/assets/css_file_folder/0015/110823/qg-components.css?v=0.1.10" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="/jquery.min.js"></script>
<script src="/formio.full.min.js"></script>
<script src="/premium.min.js"></script>
<link rel="stylesheet" href="/formio.full.min.css">
<link rel="stylesheet" href="/premium.css">
<script src="./jquery.min.js"></script>
<script src="./formio.full.js"></script>
<script src="./premium.min.js"></script>
<link rel="stylesheet" href="./formio.full.min.css">
<link rel="stylesheet" href="./premium.css">
16 changes: 10 additions & 6 deletions src/examples/SingleSignOn/SingleSignOn.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ export const createSSoForm = () => {
// window.form = form;
// This section of code is the "Form Controller"
form.on("submitDone", function submitDoneCleanup(submission) {
console.info(submission);
console.info("submission", submission);
// remove form.io api tokens after submission for security
localStorage.removeItem(`${namespace}Token`);
localStorage.removeItem(`${namespace}User`);

window.location =
"https://uat.auth.qld.gov.au/auth/realms/tell-us-once/protocol/openid-connect/logout";

function afterTimeout() {
// logout the user for security
const logoutUrl =
Expand Down Expand Up @@ -82,13 +85,14 @@ export const createSSoForm = () => {
// );

const createFormController = ({ form }) => {
console.info(`Loaded form: ${form.formio.formUrl}`);
console.info(`Loaded form: ${form.formio.formUrl}`, form);
// console.info(JSON.stringify(form.formio));
form.on("submitDone", (submission) => {
console.info(submission);
Formio.currentUser().then((userDetails) => {
console.info("submission", submission);

form.formio.currentUser({ namespace }).then((userDetails) => {
// clean up URL paramters from submission or logout redirect
console.info(userDetails);
console.info("userDetails", userDetails);
// const parent = document.getElementById("oidc_form").parentElement;
oidcform.remove();
// const oidcformNew = document.createElement("div");
Expand All @@ -115,7 +119,7 @@ export const createSSoForm = () => {

function pickForm() {
user = Formio.getUser({ namespace });
console.info(user);
console.info("user", user);
if (user) {
appendSpinner(formioDiv);
realFormSetup();
Expand Down
47 changes: 25 additions & 22 deletions src/matrixHelpers/FormioLoader/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import defaultCreateFormOptions from "../../options/createForm.options";

// polyfill plugin function to fix the namespace option doesn't pass to Formio.makeRequest
const NamespacePlugin = {
priority: 0,
preRequest(requestArgs) {
if (requestArgs.formio) {
const formioInstance = document.querySelector(
`[data-formio-form-url="${requestArgs.formio.formUrl}"]`
);
if (formioInstance) {
requestArgs.formio = JSON.parse(formioInstance.dataset.formio);
requestArgs.opts.formio = requestArgs.formio;
}
if (requestArgs.formio.options)
requestArgs.opts.namespace = requestArgs.formio.options.namespace;
}
return Promise.resolve(null);
},
};

const initFormioInstance = (formioElem, opts) => {
// if already initiated, reject
if (formioElem.dataset.formioFormUrl) return;

// if doesn't have required options, reject
if (!opts.envUrl || !opts.projectName || !opts.formName) {
console.warn(
Expand Down Expand Up @@ -61,6 +81,11 @@ const initFormioInstance = (formioElem, opts) => {
elem: formioElem,
})),
};

// register plugin
if (!Formio.getPlugin("namespacePolyfill"))
Formio.registerPlugin(NamespacePlugin, "namespacePolyfill");

Formio.createForm(formioElem, formUrl, combinedOptions).then((wizard) => {
wizard.formio = formio;
wizard.options.formio = formio;
Expand Down Expand Up @@ -128,25 +153,6 @@ const initFormioInstance = (formioElem, opts) => {
});
};

// polyfill plugin function to fix the namespace option doesn't pass to Formio.makeRequest
const NamespacePlugin = {
priority: 0,
preRequest(requestArgs) {
if (requestArgs.formio) {
const formioInstance = document.querySelector(
`[data-form-url="${requestArgs.formio.formUrl}"]`
);
if (formioInstance) {
requestArgs.formio = JSON.parse(formioInstance.dataset.formio);
requestArgs.opts.formio = requestArgs.formio;
}
if (requestArgs.formio.options)
requestArgs.opts.namespace = requestArgs.formio.options.namespace;
}
return Promise.resolve(null);
},
};

const customiseErrorMessage = () => {
const newFunc = Formio.Form.prototype.errorForm.bind({});
Formio.Form.prototype.errorForm = (err) => {
Expand Down Expand Up @@ -174,9 +180,6 @@ const initFormio = () => {
// custom error message
customiseErrorMessage();

// register plugin
Formio.registerPlugin(NamespacePlugin, "namespacePolyfill");

document.querySelectorAll("[data-formio]").forEach((formioElem) => {
const {
formioProjectName,
Expand Down