验证Jeditable字段 [英] Validate Jeditable field

查看:125
本文介绍了验证Jeditable字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网页上使用 Jeditable (张贴到CakePHP)进行输入。我希望用户只能在Jeditable字段中填写数字,因此我的想法是也使用 jQuery验证插件验证如果只使用数字,我已经在我的网站的其他部分使用这个。

I'm using Jeditable (posting to CakePHP) for input on my page. I want users to only fill in numbers in the Jeditable fields, so my idea was to also use the jQuery validation plugin to validate if only numbers are used, I already use this in other parts of my site.

Jeditable动态创建一个表单,当你点击div,

Jeditable dynamically creates a form with an input when you click on the div, so there seems to be nothing for Jquery validate to bind to and it doesn't seem to work as normal.

我可以通过Jeditable设置表单的类名称它只有一个类atrribute),创建的输入只有一个name属性默认为名称。

I'm able to set the class name of the form through Jeditable (it only has a class atrribute), the created input only has a name attribute which defaults to "name".

我的问题:


  • 这是一个只需要数字的好方法?

  • 如果是这样,如何使其与Jquery一起使用validate

  • 如果没有,更好的解决方案是什么?

我可能会得到;)

推荐答案

您可以直接在jeditable中使用jQuery验证插件来验证表单的字段

You can use jQuery validation plugin directly in jeditable to validate the fields of your form

$('.edit').editable(your_url, {
    onsubmit: function(settings, td) {
        var input = $(td).find('input');
        $(this).validate({
            rules: {
                'nameofinput': {
                    number: true
                }
            },
            messages: {
                'actionItemEntity.name': {
                    number: 'Only numbers are allowed'

                }

            }
        });

        return ($(this).valid());
    }
});

这篇关于验证Jeditable字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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