Home › Forums › Modern DFFS › Redirect after save/cancel
- This topic has 21 replies, 3 voices, and was last updated 1 year, 3 months ago by Alexander Bautz.
-
AuthorPosts
-
-
February 16, 2023 at 19:49 #36443
Is there a way in Modern DFFS to redirect users to a specified page after saving or cancelling a form?
-
February 16, 2023 at 21:15 #36444
To redirect after save you must set up a rule triggering on “After save of the form” and add an action “Call a function”. Add the name “redirectToCustomUrl” in the “Function name” field and then add this function to your custom js:
function redirectToCustomUrl(){ location.href = "https://spjsworks.com"; }
I haven’t currently added a method to detect cancel button click (or X in the top right corner), but will look at adding a trigger to detect that also.
Alexander
-
February 16, 2023 at 23:32 #36445
Thank you. Yes, in this instance I am sending users to the form from another page, so I want them to come back whether they save or cancel in the form. This would also apply if I just show them the display form for an item and they close it. I would like to send them back to the page of my choice. Adding a way to detect cancelling would be very helpful in order to handle both cases (save and cancel or close).
-
February 17, 2023 at 17:09 #36446
I’ll add support for detecting that in the next version.
Alexander
-
February 17, 2023 at 22:55 #36447
Thank you! I really appreciate it.
-
February 20, 2023 at 18:45 #36452
I have published a new version with support for detecting “cancel” in a form – you find the change log over at spjsworks.com.
Let me know how it works out.
Alexander
-
-
March 6, 2023 at 17:42 #36515
I am finally getting back around to try this out and am having a bit of trouble trying to figure out how to trigger a function on cancelling a form. I don’t see a cancel event in the triggers for the rules. How do I attach my function to a cancel event?
I appreciate your help.
-
March 6, 2023 at 19:45 #36516
Sorry for not specifying that you must use custom js to do this – see this forum thread for an example: https://spjsblog.com/forums/topic/custom-js-examples/
Alexander
-
-
March 6, 2023 at 19:54 #36517
Thanks for your reply. I did see those examples, but I haven’t successfully gotten my functions to trigger when the form is closed or cancelled. I am not seeing the cancel event as something I can use as a trigger.
Attachments:
-
March 6, 2023 at 20:01 #36519
That is correct, the trigger is the function itself – if it exists in your custom js it will be triggered when you cancel the form.
Just drop this in your forms custom js:
function dffs_PostCancelAction() { // Do something if the item is cancelled - for example redirect to another page location.href = "https://contoso.com/CancelMsg"; }
What is it you want to do when a form is cancelled?
Alexander
-
March 6, 2023 at 20:57 #36520
For some reason it doesn’t seem to be working for me. We are still running v1.0.12.0, but I believe that version includes support for detecting the cancel event.
I have this in the Custom JS of the New form:
function saveCancelRedirect() {
let searchParams = new URL(document.location).searchParams;
let dffsSource = decodeURIComponent(searchParams.get(“DFFSSource”));
console.log(‘dffsSource:’);
console.log(dffsSource);
console.log(typeof dffsSource);if (dffsSource !== undefined && dffsSource !== null && dffsSource !== ‘null’) {
console.log(‘Redirect to ‘ + dffsSource);
}
}function dffs_PostSaveAction() {
saveCancelRedirect();
}function dffs_PostCancelAction() {
saveCancelRedirect();
}I am able to trigger the function by clicking a button, but it is not triggering when I cancel or close the form.
-
March 6, 2023 at 20:58 #36521
I also tried with this but still, I can see the action take place on clicking a button, but not on cancelling the form.
function saveCancelRedirect() {
let searchParams = new URL(document.location).searchParams;
let dffsSource = decodeURIComponent(searchParams.get(“DFFSSource”));
console.log(‘dffsSource:’);
console.log(dffsSource);
console.log(typeof dffsSource);if (dffsSource !== undefined && dffsSource !== null && dffsSource !== ‘null’) {
location.href = dffsSource;
}
} -
March 6, 2023 at 21:05 #36522
I realized I didn’t really explain my purpose. I want to set up the function so it can dynamically pull the redirect destination from the URL search parameters because the page I link FROM may change and I am putting the current page in the search parameters under a “DFFSSource” parameter. If that parameter is present, I want to redirect users to whatever URL is passed. I am testing with “https%3A%2F%2Fwww%2Egoogle%2Ecom” as the source and it logs correctly in the console as https://www.google.com just before navigating to Google when I test by clicking a button. When I cancel the form, nothing logs to the console and nothing happens. I don’t get errors, I just don’t get anything.
-
-
March 6, 2023 at 22:57 #36523
You are right, this doesn’t work… I had a typo in the code and it only works if you use it in a “child form” (view / edit of a vLookup or when opening a lookup item).
I’ll get this fixed in the next version later this week.
Sorry for the inconvenience!
Alexander
-
March 6, 2023 at 23:01 #36524
No problem! Thank you for all you do to make this a great product that works for so many different scenarios. I look forward to testing it out again after the next version comes out.
-
-
March 7, 2023 at 20:55 #36528
I have published a new version – please let me know how it works out.
Alexander
-
March 8, 2023 at 23:00 #36535
It looks like everything is working now! Thank you for publishing the new version with the update.
-
August 10, 2023 at 16:39 #37023
Hi Alexander,
I’d like to redirect the user to our homepage instead of the default list when a form is saved or cancelled. I tested the following codes in the custom JS tab on all forms and I am still being redirected to a list instead of the intended URL. (used google URL for confidentiality purposes). Can you please take a look at the codes I’m using for any errors?
function dffs_PostCancelAction() {
location.href = “https://google.com”;
}function dffs_PostSaveAction() {
location.href = “https://google.com”;
}Currently operating on the following versioning of DFFS:
Dynamic Forms for SharePoint v4.4.5.27 – July 30, 2023
CSS version: 4.51 / 4,51
spjs-utility version: 1.356
Loader version: v2-
August 10, 2023 at 16:44 #37024
UPDATE TO CODES:
For some reason when I posted this reply the code was corrupted. I attached a screenshot to this post
Attachments:
-
-
August 10, 2023 at 19:00 #37026
Hi Sarah,
The method you refer to is for the Modern DFFS version. I see from the version details that you use the classic DFFS and you must use code like this:function dffs_PreSaveAction(){ spjs.dffs.redirect("https://The_address_to_redirect_to_after_save",false); }
Alexander
-
August 15, 2023 at 15:38 #37032
Thank you, I tried this and it worked for redirecting on save.
Is there a similar functionality to redirect on cancel? I tried PreCancelAction, PreCloseAction, with the same syntax and neither worked
-
August 15, 2023 at 19:26 #37034
Hi,
There is no built in method, but you can attach a click function to the cancel button by adding this to your custom js:jQuery("input[id$='diidIOGoBack']").click(function(){ location.href = "https://spjsblog.com/DFFS"; });
Alexander
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.