Wiki source code of Export (Persistence)
Hide last authors
author | version | line-number | content |
---|---|---|---|
15.1 | 1 | {{figure image="export_persistence_en.png" clear="h1"}} | |
2 | User interface for editing actions of type //Export (Persistence)//. | ||
1.3 | 3 | {{/figure}} | |
1.1 | 4 | ||
15.1 | 5 | Actions of type //export (persistence)// allow you to export the data of a form record, i.e. the data that has been submitted with the form. With a little bit of Javascript code, the exported data can be imported again later. This way it becomes possible to save form record data locally and restore it from a local backup. Filling form fields with data stored in an XML file is also possible via the actions of type [[//Import form values from XML//>>Formcycle.UserInterface.MyForms.WorkflowProcessing.Actions.ImportXML]]. | |
1.1 | 6 | ||
15.1 | 7 | == Options == | |
1.1 | 8 | ||
15.1 | 9 | ; Output file name | |
10 | : The name for the export file. | ||
1.1 | 11 | ||
15.1 | 12 | ; Attach file to form record | |
13 | : Determines whether the generated output file should be attached to the operation. | ||
1.1 | 14 | ||
15.1 | 15 | == Importing form data from a persistence file == | |
1.1 | 16 | ||
15.1 | 17 | When you open a form and the form contains a non-empty upload field named {{code language="none"}}fcp_persistence{{/code}}, or some other upload field contains a file whose file name without the extension is {{code language="none"}}fcp-persistence{{/code}}, form fields are pre-filled with the data form the persistence file. | |
8.4 | 18 | ||
15.1 | 19 | The following example code makes it possible to realize this process with a button. The target of the form is set to its own URL when it is sent and all input fields except the upload field are deactivated. Subsequently, a submit of the form is executed which loads the contents of the file. | |
8.4 | 20 | ||
21 | {{code language="javascript"}} | ||
8.5 | 22 | $('BUTTON[name="btnLoad"]').on('click', function(){ | |
23 | $('.xm-form').attr('action', window.location); | ||
24 | $('.xm-form input').not('[name=fcp_persistence]').attr('disabled', "disabled"); | ||
25 | $('.xm-form textarea').attr('disabled', "disabled"); | ||
26 | $('.xm-form select').attr('disabled', "disabled"); | ||
27 | $('.xm-form').submit(); | ||
8.4 | 28 | }); | |
29 | $('[xn="fcp_persistence"] .img-uploaded-preview').visible(false); | ||
30 | {{/code}} | ||
31 | |||
15.1 | 32 | Alternatively the following code can be used: | |
13.6 | 33 | ||
13.3 | 34 | {{code language="javascript"}} | |
35 | $('document').ready(function(){ | ||
36 | var nameOfTriggerButton= "btnLoad"; | ||
13.7 | 37 | ||
13.3 | 38 | var form = $("<form>", { | |
39 | action:"?", | ||
40 | method:"post", | ||
41 | enctype:"multipart/form-data" | ||
42 | }).appendTo('body'); | ||
13.7 | 43 | ||
13.3 | 44 | var upload = $("<input>", { | |
45 | type:"file", | ||
46 | name:"fcp_persistence" | ||
47 | }).appendTo(form); | ||
13.7 | 48 | ||
13.3 | 49 | upload.change(function(){form.submit()}); | |
50 | $('BUTTON[name="'+nameOfTriggerButton+'"]').click(function(){upload.trigger('click')}); | ||
51 | }) | ||
52 | {{/code}} | ||
53 | |||
13.2 | 54 | {{info}} | |
15.1 | 55 | [[You may also download an example form>>attach:Local import and export.zip]] illustrating this process and how to setup the workflow. | |
13.2 | 56 | {{/info}} |