简体   繁体   English

我试图在django中制作一种动态性质的形式,该形式会根据用户更改模板中的字段数。 屏幕截图如下

[英]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 呈现具有所有字段的简单表单,首先查看组件idname名称是什么

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.

相关问题 使用动态数量的字段制作Django表单类 - Making a Django form class with a dynamic number of fields Django-表单上的动态字段数 - Django - dynamic number of fields on a form 如何修复我的 Django model 以存储用户输入的多个字符串列表。 将来可以检索哪个 object? - How can I fix my Django model to store multiple lists of strings inputted by the user. Which can then be retrieved in the future as an object? Django管理表单:动态字段列表导致KeyError,我可以通过按F5绕过它,为什么? - Django admin form : dynamic fields list causes a KeyError which I can bypass just by pressing F5, why? 如何获取django模板中的表单字段数? - How to get the number of form fields in a django template? 向Django管理表单添加动态数量的字段 - Add a dynamic number of fields to Django admin form Django表单,用户输入字段未在模板中呈现 - Django Form, User input fields not rendering in template 编写一个对用户计数的程序。 让用户输入起始编号、结束编号和计数的数量 - Write a program that counts fort he user. Let the user enter the starting number, the ending number, and the amount by which to count 如果没有输入,哪个Django模型字段不会引发IntegrityError? - Which Django model fields won't raise IntegrityError if no input is given? 如何为下面给出的代码片段添加“格式”? - How can I add “format” for the piece of the code which is given below?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM