Home › Forums › Classic DFFS › Looking for a Way to use onclick function to Archive Form Entries
Tagged: Archive button Command Function
- This topic has 5 replies, 2 voices, and was last updated 3 years, 8 months ago by Alexander Bautz.
-
AuthorPosts
-
-
April 2, 2021 at 18:05 #33141
I am looking for a way to be able to archive and unarchive form entries using onclick function at the top of the edit form. Ideally the business would like to open a form entry and click a button or choice field y/n (labeled archive) to trigger a popup box that allows the user to add archive details. Once the details are added then the user would click save/or submit and that would trigger an action that would remove the form from the default view in the library. Ideally they would like to be able to unarchive the form the same way and have it go back into the default view library. Is this possible within DFFS?
-
April 3, 2021 at 09:13 #33145
Hi,
Yes, this is possible. Add this to your Custom JS:function flagAsArchived(){ spjs.modal.add({ "title": "Archive this item", "html": "<div style='font-size:1.2em;'>Archive details</div><textarea id='archiveDetailsTextarea' style='width:100%;box-sizing:border-box;height:100px;'></textarea>", "closeOnOK": false, "ok": function(){ setFieldValue("Your_boolean_archived_field", true); var msg = jQuery("#archiveDetailsTextarea").val(); setFieldValue("Your_archive_details_note_field", msg); spjs.dffs.triggerSave(); }, "cancel": function(){ // Close dialog }, "showClose": false, "allowMaximize": false, "resizable": false }); }
Then create a button or a rule where you call this function.
Change “Your_boolean_archived_field” and “Your_archive_details_note_field” to match your field names. Also change the filter in your default list view to not show the items flagged as “Archived”.
Using this same approach you can create another function to un-archive the item by changing the setFieldValue of “Your_boolean_archived_field” to false.
Alexander
-
April 5, 2021 at 14:54 #33149
This has worked great! Thank you. I have the unarchive button created to reverse the archive function and have updated the field names and setfieldfalue to false. But when the Unarchive button is clicked, it does not make the entry visible again in the default view for the library. Also, is there a way to make the unarchive button visible only if the entry is currently archived? Instead of seeing both buttons on the edit form?
-
April 5, 2021 at 18:57 #33156
If you give each of the buttons an ID and hide them initially:
<input type="button" id="archive_btn" style="display:none;" value="Archive" onclick="the_archive_function()"> <input type="button" id="undo_archive_btn" style="display:none;" value="Undo archive" onclick="the_undo_archive_function()">
You can now set up two rules – one for “Archived = yes” and one for “Archived = no” – have them run ON FORM LOAD only and add the ID of the button you want to show in the “Visible headings or elements” textarea. This will now show the correct button based on the archived field being checked or unchecked.
Regarding the visibility in list view: you must ensure that the code actually sets the “Archived” field to false when you run the function and that the view is actually filtered on that field.
Alexander
-
April 14, 2021 at 15:33 #33205
Hello,
There is still one piece of this setup that I can’t get right. How do I get the details the user adds to the popup box copied over to an actual form field? Or is it possible to have the popup box be an actual form field itself? That would eliminate the need to have the contents entered into the popup box copied over to a form field. Thanks again for all of your help on this.
-
April 15, 2021 at 15:49 #33219
This is happening in these lines in the original code:
// Getting the value from the textarea var msg = jQuery("#archiveDetailsTextarea").val(); // Writing the value to the form - you must replace "Your_archive_details_note_field" with the internal name of your field. setFieldValue("Your_archive_details_note_field", msg);
Alexander
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.