DOJO:如何在ajax调用后重新启动表单元素? [英] DOJO : How do you reinitiate form elements after ajax call?

查看:151
本文介绍了DOJO:如何在ajax调用后重新启动表单元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Zend Framework& Dojo Toolkit和任何帮助将不胜感激。这是一个问题:



我有一个使用Zend Framework表单类渲染的表单,它具有ajax单选按钮选择。单击其中一个单选按钮将发送一个ajax请求到另一个控制器,它没有布局,只是一个渲染的表单。然后,ajax请求将使用新的表单选项填充div。



问题是,当我将div的innerHTML替换为ajax响应时,所有表单输入和元素不会继承相同的Dojo样式和表单验证。



我想知道有没有办法在ajax通话后重新启动表单元素?



我试过使用我发现和修改的代码,这个例子稍微修改,但是它没有起作用。如果我使用行$ dojo.parser.parse(div); 没有任何改变(例子中的rg_adress是放置在DOM上的表单元素的ID)。这是rg_address的console.log:

 < input type =textdojotype =dijit.form.ValidationTextBox 
required =1invalidmessage =收件人的名字
value =name =rg_addressid =rg_addressclass =textbox/>

onClick ='

dojo.xhrGet({
url:/ transfer / newrecipient /,
handleAs:text,
timeout:10000,//以毫秒为单位的时间

// LOAD函数将在成功响应时调用
load:function(response,ioArgs){
$ (#newRecipient)。html(response);
$(#newPayMethod)。html();
$(#newPayDetail)。html();

var div = dojo.byId(rg_address);
console.log(div);
dojo.parser.parse(div);

返回响应;
},

//错误情况下将调用ERROR函数
error:function(response,ioArgs){
$( #newRecipient)html(加载注册表单时出错);
$(#newPayMethod)。html();
$(#newPayDetail ;
return response;
}

});'

谢谢,
Dural

解决方案

我有同样的问题d我找到一个可能的答案:



http://o.dojotoolkit.org/forum/dijit-dijit-0-9/dijit-support/dijit-parse-after- ajax-call-again



根据我的理解,您需要在函数中执行类似这样的操作,以处理从ajax调用:

  function updateform(data)
{
var targetNode = dojo.byId(\\ \\第2步\);
targetNode.innerHTML = data;
dojo.parser.parse(targetNode);
}

这适用于:

  Zend_Dojo_View_Helper_Dojo :: setUseDeclarative(); 

但我想使用编程。我会提出一个问题。


I'm trying to do a couple of things using Zend Framework & Dojo Toolkit, and any help would be appreciated. Here's the problem:

I have a form that is rendered with the Zend Framework form class, which has an ajax radio button selection. Clicking one of these radio buttons will send an ajax request to another controller, which has no layout, just a rendered form. The ajax request will then populate a div with the new form options.

Problem is, when I replace the innerHTML of the div with the ajax response, all the form inputs and elements are not inheriting the same Dojo styling and form validation.

I was wondering if there is a way to reinitate form elements after an ajax call?

I have tried to use the code attached which I found and modified slightly for this example, however it did not work. If I use the line dojo.parser.parse( div ); nothing changes (rg_adress in the example is the ID of a form element that is placed on the DOM). Here is the console.log of rg_address:

 <input type="text" dojotype="dijit.form.ValidationTextBox" 
   required="1" invalidmessage="The first name of the recipient"
   value="" name="rg_address" id="rg_address" class="textbox"/>

  onClick='

  dojo.xhrGet( {
    url: "/transfer/newrecipient/",
    handleAs: "text",
    timeout: 10000, // Time in milliseconds

    // The LOAD function will be called on a successful response.
    load: function(response, ioArgs) {
  $("#newRecipient").html(response);
      $("#newPayMethod").html("");
  $("#newPayDetail").html("");

  var div = dojo.byId("rg_address");
  console.log( div );
  dojo.parser.parse( div );

  return response;
    },

    // The ERROR function will be called in an error case.
    error: function(response, ioArgs) {
  $("#newRecipient").html("Error loading registration form");
  $("#newPayMethod").html("");
  $("#newPayDetail").html("");
  return response;
    }

  });'

Thanks, Dural

解决方案

I have the same question and I found a possible answer:

http://o.dojotoolkit.org/forum/dijit-dijit-0-9/dijit-support/dijit-parse-after-ajax-call-again

From what I understand, you'd need to do something like this in your function that is called to handle the data received from the ajax call:

function updateform(data)
{
    var targetNode = dojo.byId(\"step2\");
    targetNode.innerHTML = data;
    dojo.parser.parse(targetNode);
}

This works with:

Zend_Dojo_View_Helper_Dojo::setUseDeclarative();

But I'd like to use programmatic. I'll post a question about that.

这篇关于DOJO:如何在ajax调用后重新启动表单元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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