How to load values from a cookie to a form which is in wizardpane (dojo)

≡放荡痞女 提交于 2019-12-13 07:26:11

问题


I am trying to automatically fill a form from cookie data if the user already visited the site and checks the remember me checkbox...my cookie contains an array of data...i am trying to fill the form with array data..

here is the sample code

Cookie_check: function () {
            var Cookie_Array = registry.byId("form").getChildren();
            console.log(Cookie_Array);
            var Cookie_Info = new Array();
            dArrayUtil.forEach(Cookie_Array, function (item, i) {
                Cookie_Info.push(item.value);
            });
            console.log(Cookie_Info);
            //set cookie
            cookie("cookie_name", dJson.toJson(Cookie_Info), { expires: 5 });

            //get cookie infor into an array
            var cookie_name = dJson.fromJson(cookie("cookie_name"));
            console.log(cookie_name);

            //fill the form using the cookie information


            dArrayUtil.forEach(cookie_name, function (item) {

                    console.log(item);
                    registry.byId("form").setFormValues(item);

            });

        },

I have couple of questions-- 1. How to check if there is a cookie already and set the form with the cookie information?(in the above function i am missing the condition when i will be filling the form with cookie data (array)) 2. How do i pass this function on load of the wizard pane?

Any help greatly appreciated.

Thank you.


回答1:


How does this cookie crumble?

require(["dojo/dom-form", "dojo/cookie"], function(domForm, dCookie){

  function beforeFormSubmit() {
    dCookie(
         "formdata",
         domForm.toJson("myForm"),
         {expires: 5}
    );
  }
  function onWizardPaneShow() {
    var formData = dCookie("formdata");
    dojo.query("#myForm input").forEach(function ( inputEl) { 
       if(inputEl.name && formData[inputEl.name])
          inputEl.value = formData[inputEl.name];
    });
  }
});


来源:https://stackoverflow.com/questions/10536307/how-to-load-values-from-a-cookie-to-a-form-which-is-in-wizardpane-dojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!