如何将值从一个cookie加载到在wizardpane(dojo) [英] How to load values from a cookie to a form which is in wizardpane (dojo)

查看:144
本文介绍了如何将值从一个cookie加载到在wizardpane(dojo)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户已经访问过网站并检查记住我的复选框,我试图从cookie数据自动填充表单...我的cookie包含数据数组...我试图用数组数据填充表单..

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..

这里是示例代码

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);

            });

        },

我有几个问题 -
1.如何检查是否有一个cookie已经和设置表单的cookie信息?(在上面的函数我缺少条件,当我将填充表单的cookie数据(数组))
2。如何在向导窗格加载时传递此函数?

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?

任何帮助非常感谢。

推荐答案

这个cookie如何崩溃?

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];
    });
  }
});

这篇关于如何将值从一个cookie加载到在wizardpane(dojo)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆