Estoy tratando de guardar los datos del formulario como una cookie y luego completar un formulario si el usuario tiene una cookie coincidente en la carga de la página. Parece funcionar según lo previsto, pero luego, cuando hago clic en cualquier entrada en el formulario, hace que se borren los valores establecidos por javascript.
Mi JS:
// when the user click on the hs-submit button, serialize the form data and save it in a cookie $('.hs-submit').click(function(e){ e.preventDefault(); var formID = $(this).attr('data-form'); var form = $(`.form-${formID}`).find('form'); var formData = form.serializeArray(); // convert the form to a string var data = JSON.stringify(formData); $.cookie(`hs-form-${formID}`, data, { expires: 7, path: '/' }); }); // when the user loads the page, if they have a cookie for the form, populate the form if($.cookie('hs-form-1')){ var formData = $.cookie('hs-form-1'); // convert the formData to parsedData var parsedData = JSON.parse(formData); var form = $(`.form-1`).find('form'); $.each(parsedData, function(i, field){ form.find(`[name="${field.name}"]`).val(field.value); }); }