[英]I tried making a form of dynamic nature in django which change the number of fields in template as per user. screenshot of which is given below
I'm planning to make a dynamic forms in django
which takes 3 basic fields one char type, one date type and one numeric integer value. 我计划在
django
制作一个动态表单,该表单需要3个基本字段,一个字符类型,一个日期类型和一个数字整数值。 I use basic django model
forms and render method to save the form in database. 我使用基本的
django model
表单和渲染方法将表单保存在数据库中。 But I'm unable to perform that operation in this dynamic form. 但是我无法以这种动态形式执行该操作。 Any type of help will be appreciated.
任何类型的帮助将不胜感激。
You can do that in jquery/javascript in django template 您可以在Django模板的jquery / javascript中做到这一点
Render simple form with all fields first see what are name of components id
or name
呈现具有所有字段的简单表单,首先查看组件
id
或name
名称是什么
then you show the first field and hide the other two on pageload 然后您显示第一个字段,并在pageload上隐藏其他两个字段
$("#idofcomponent2").hide()
$("#idofcomponent3").hide()
$("#idofcomponent1").on("focusout",function(){
//show second component here and hide the first
$(this).hide();
$("#idofcomponent2").show()
});
$("#idofcomponent2").on("focusout",function(){
//show second component here and hide the first
$(this).hide();
$("#idofcomponent3").show()
});
I was not able to test it. 我无法测试。 Please let me know.
请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.