简体   繁体   English

Joomla 2.5模态弹出组件形式

[英]Joomla 2.5 modal popup component form

I'm trying to modify a Joomla component to achieve some ajax functionality to make things a little bit more streamlined for my website users. 我正在尝试修改Joomla组件以实现一些Ajax功能,以使网站用户的工作更加简化。 I've changed the information below to keep the project a little anonymous because I'm paranoid :-) 我更改了以下信息,以使项目保持匿名状态,因为我很偏执:-)

What I want to achieve is simple in my head: 我想实现的目标很简单:

-> User lands on 'order' page in xyz component ->用户进入xyz组件的“订单”页面

-> If there are no delivery addresses for this user on the order page, give a link to create one ->如果在订购页面上没有该用户的收货地址,请提供一个链接以创建一个

-> When user clicks 'Add an address' a modal window appears and does an ajax request to the 'addaddress' page which has the form to add an address ->当用户单击“添加地址”时,将出现一个模式窗口,并向具有“添加地址”形式的“添加地址”页面发出ajax请求

-> Modal does not display the full page, instead it only displays the form and the essential (required) form fields ->模态不显示整页,而是仅显示表单和必填(必填)表单字段

-> User inputs address information and clicks button to submit the form. ->用户输入地址信息,然后单击按钮提交表单。

-> The fields are validated then posted ->验证字段然后发布

-> The modal closes ->模式关闭

-> The field which has the delivery addresses on the originating 'order' page is refreshed and now includes the new address. ->在原始“订单”页面上具有交货地址的字段将刷新,现在包括新地址。 This should not refresh the entire page as the user might have put data into the other form elements. 这不应刷新整个页面,因为用户可能已将数据放入其他表单元素中。 This is important. 这个很重要。

OK, so now you know what I want to achieve, let me introduce you to what I currently have. 好,现在您知道了我要实现的目标,让我向您介绍当前的目标。

-> User lands on 'order' page in xyz component ->用户进入xyz组件的“订单”页面

-> If there are no delivery addresses for this user on the order page, give a link to create one ->如果在订购页面上没有该用户的收货地址,请提供一个链接以创建一个

I have written a simple php if statement that creates an anchor link with the text 'Add an address' and id 'addNewAddress' 我已经编写了一个简单的php if语句,该语句使用文本“添加地址”和ID“ addNewAddress”创建锚链接

-> When user clicks 'Add an address' a modal window appears and does an ajax request to the 'addaddress' page which has the form to add an address ->当用户单击“添加地址”时,将出现一个模式窗口,并向具有“添加地址”形式的“添加地址”页面发出ajax请求

I am using a mootols plugin called SimpleModal from http://simplemodal.plasm.it 我正在使用来自http://simplemodal.plasm.it的名为SimpleModal的Mootols插件

-> Modal does not display the full page, instead it only displays the form and the essential (required) form fields ->模态不显示整页,而是仅显示表单和必填(必填)表单字段

I have extended the functionality of the modal to allow me to inject some mootools filtering because I only want to display the form, nothing else. 我扩展了模态的功能,允许我注入一些mootools过滤,因为我只想显示表单,仅此而已。 I have added this as a new parameter called getSomething that I can inject if I need to. 我已将此添加为名为getSomething的新参数,可以在需要时进行注入。

//SIMPLEMODAL
$("addNewAddress").addEvent("click", function(){
  var SM = new SimpleModal({"width":600});
      SM.addButton("Action button", "btn primary", function(){
          $('addressForm').submit();
          this.hide();
      });
      SM.addButton("Cancel", "btn");
      SM.show({
        "model":"modal-ajax",
        "title":"New address",
        "param":{
          "url":"index.php?option=com_address&modal=true",
          "getSomething":"#addressForm",
          "onRequestComplete": function(){}
        }
      });
});

And this is the function that it calls: 这就是它调用的函数:

else if (param.getSomething.match(elid))
        {

            // Request HTML
            this.request = new Request.HTML({
                evalScripts:false,
                url: param.url,
                method: 'get',
                onRequest: function(){},
                onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
                    var f = responseElements.filter(param.getSomething);
                    $('simple-modal').removeClass("loading");
                    $('simple-modal').getElement(".contents").adopt(f);
                    param.onRequestComplete();

                    // Execute script page loaded
                    eval(responseJavaScript)

                    // Resize
                    this._display();

                    // Add Esc Behaviour
                    this._addEscBehaviour();
                }.bind(this),
                onFailure: function(){
                    $('simple-modal').removeClass("loading");
                    $('simple-modal').getElement(".contents").set("html", "loading failed")
                }
            }).send();
        }

*Now, everything up to this point I have managed to get working but I can't figure out the next part. *现在,到目前为止,我已经设法开始工作,但是我无法弄清楚下一部分。 * *

-> User inputs address information and clicks button to submit the form. ->用户输入地址信息,然后单击按钮提交表单。

At the end of the ajax request url, you might notice that I sent the modal=true request, this is so that I can hide certain elements on the form that I don't need to be displayed in the modal window - the form's own submit button is hidden when called from the modal. 在ajax请求URL的末尾,您可能会注意到我发送了modal = true请求,这是为了隐藏不需要在模式窗口中显示的表单上的某些元素-表单本身从模式调用时,提交按钮被隐藏。

-> The fields are validated then posted ->验证字段然后发布

If I call the 'addaddress' page without the modal, the form has it's own validation. 如果我在不使用模式的情况下调用“ addaddress”页面,则表单具有其自己的验证。 Using the modal however, when I click submit, no validation happens and the address is added without any validation. 但是,使用模式时,当我单击“提交”时,不会进行任何验证,并且地址将被添加而无需进行任何验证。 I need to implement some validation to the fields using a standalone validation from within the modal itself. 我需要使用模态本身内部的独立验证对字段进行一些验证。

-> The modal closes ->模式关闭

At the moment, when the form is posted I get redirected to the ' viewaddresses ' page but I'm confident I can fix this on my own. 目前,当表单发布后,我将重定向到“ viewaddresses ”页面,但我相信我可以自己解决此问题。 Instead I just want the modal to close. 相反,我只想关闭模式。

-> The field which has the delivery addresses on the originating 'order' page is refreshed and now includes the new address. ->在原始“订单”页面上具有交货地址的字段将刷新,现在包括新地址。 This should not refresh the entire page as the user might have put data into the other form elements. 这不应刷新整个页面,因为用户可能已将数据放入其他表单元素中。 This is important. 这个很重要。

This is self explanatory but I'm not sure where to even begin. 这是不言自明的,但我不确定从哪里开始。

I think I've been as clear as I can be, but if you need anything else, please let me know. 我想我已经很清楚了,但是如果您还有其他需要,请告诉我。

I really appreciate any help you can provide. 我非常感谢您可以提供的任何帮助。

What you are maybe missing is how to trigger a form submit. 您可能缺少的是如何触发表单提交。

  • You can submit a form with: $('myForm').fireEvent('submit'); 您可以使用以下方式提交表单: $('myForm').fireEvent('submit');

So, using your example I changed the code of one of the modal buttons to: 因此,使用您的示例,我将模式按钮之一的代码更改为:

SM.addButton("Submit button", "btn primary", function () {
    $('addressForm').fireEvent('submit');
});

In the Mootools Form.Validator you can capture the formValidate event. 在Mootools Form.Validator中,您可以捕获formValidate事件。 Description: 描述:

formValidate - (function) callback to execute when the form validation completes; formValidate-(函数)在表单验证完成时执行的回调; this function is passed three arguments: a boolean (true if the form passed validation); 此函数传递三个参数:布尔值(如果表单通过了验证,则为true); the form element; 表单元素; and the onsubmit event object if there was one (otherwise, passed undefined). 和onsubmit事件对象(如果存在)(否则,传递未定义)。

I'm not sure why the form is not submited when the submit is fired programatically, but anyway you can add a new .submit() inside this function that checks the validator boolean result. 我不确定为什么以编程方式触发提交时为什么不提交表单,但是无论如何,您可以在此函数内添加一个新的.submit()来检查验证器的布尔结果。

So you can do like this: 所以你可以这样:

new Form.Validator.Inline(myForm, {
    onFormValidate: function (bool, element) {
        if (bool) {
            element.submit();
        }
    }

Demo here 在这里演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM