Django Javascript表单验证 [英] Django Javascript form validation

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

问题描述

我想添加js验证到我的表单,并且该验证应该没有请求到我的服务器。



所以,说,我打开一个页面与表单,做一些错误和js代码显示我(没有单一的请求到服务器),说,这个字段是必需的,这个字段太短,这个字段应该是一个数字等。



主要想法 - DRY - 这个js代码应该是自动生成的,和/或它应该从表单获得验证规则。



现在我会通过编写自定义js代码(或使用某种形式的验证库)来实现此类验证,并且我需要在表单和js代码中复制验证规则。这不是DRY :)另外我会收到一些与错误信息相关的问题。



是否有解决方案需要我?



谢谢。

解决方案

我在我的书签中发现了这篇文章,但我还没有尝试过。



http:// eikke .com / django-validation-an-introduction /



这是一个小帖子,解释了如何从Newform形式生成客户端验证JavaScript(保持你干)。一些代码也可以在一个git仓库中使用p>

I'd like to add js validation to my forms, and that validation should be done without requests to my server.

So, say, I open a page with form, make some errors and js code show me (without single request to the server) that, say, this field is required, this field is too short, this field should be a number etc.

The main idea - DRY - this js code should be auto-generated and/or it should get validation rules from form.

Now I would implement such validation by writing custom js code (or use some form validation libraries), and I need to duplicate validation rules - in forms and in js code. This is not DRY :) Also I'll get some problems connected with error messages.

Is there solution for my need?

Thanks.

解决方案

i found this post in my bookmarks, but i haven't tried it out myself yet.

http://eikke.com/django-validation-an-introduction/

it's a small post that explains how to generate client side validation javascript from a Newform form (keeping you dry). some code is also available in a git repository

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

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