diff --git a/app/admin/form.rb b/app/admin/form.rb index 0363616..4db17ea 100644 --- a/app/admin/form.rb +++ b/app/admin/form.rb @@ -4,7 +4,7 @@ menu priority: 10 permit_params :name, :style, :title, :body, :redirect_url, :action, :success, :created_by_id, :use_recaptcha, :recaptcha_key, :recaptcha_secret, :origin, - form_fields_attributes: [:id, :field_id, :label, :help, :required, :placeholder, :position, :_destroy, + form_fields_attributes: [:id, :field_id, :label, :help, :required, :placeholder, :position, :persist, :_destroy, campaign_options_attributes: %i[id campaign_code label position _destroy],], campaign_codes: [] @@ -87,6 +87,7 @@ fields_f.input :placeholder, hint: "Override field placeholder." fields_f.input :help, hint: "Optional help message." fields_f.input :required, as: :boolean, label: "Is field required?" + fields_f.input :persist, as: :boolean, label: "Store/retrieve value from other forms?" fields_f.has_many :campaign_options, allow_destroy: true, sortable: :position, heading: "Campaigns" do |campaigns_f| campaigns_f.inputs do diff --git a/app/javascript/campaign-form.js b/app/javascript/campaign-form.js index bc5da52..69e21fd 100644 --- a/app/javascript/campaign-form.js +++ b/app/javascript/campaign-form.js @@ -42,6 +42,17 @@ if (typeof window.campaignForms === 'undefined') { window._satellite.track('aa-email-signup') } + const cfPersisted = Array.from( + document.querySelectorAll("input[cfpersisted]") + ).map(({ id, value }) => ({ + key: id.match(/(.*)_\d+/)[1], + value + })); + sessionStorage.setItem( + "campaignFormsPersistedInputs", + JSON.stringify(cfPersisted) + ); + // Call optional success callback if defined if (typeof campaignForm.successCallback === 'function') { window.campaignForm.successCallback(data.master_person_id) @@ -136,6 +147,16 @@ if (typeof window.campaignForms === 'undefined') { } } }) + const cfPersisted = JSON.parse( + sessionStorage.getItem("campaignFormsPersistedInputs") + ); + cfPersisted.forEach(({ key, value }) => { + const element = document.querySelector(`input[cfpersisted][id^='${key}']`); + if (element) { + element.value = value; + element.readOnly = true; + } + }); } })(jQuery) } @@ -155,4 +176,4 @@ $(document).ready(function() { $("[id^='cf_US_State_']").show() } }) -}) \ No newline at end of file +}) diff --git a/app/views/fields/_input.html.erb b/app/views/fields/_input.html.erb index e0e0265..ef55390 100644 --- a/app/views/fields/_input.html.erb +++ b/app/views/fields/_input.html.erb @@ -1,4 +1,4 @@