将多个单选按钮与单个文本框关联(Associate multiple radio buttons with a single textbox)
我不擅长前端和HTML是我理想的在这里工作(如果我可以避免在这里使用js / jquery)。 我有一个带有多个单选按钮的文本框 - 例如,item1,item2,... item5。 每个item1,2 ......对应一个字段。 当用户在文本框中输入“abc”并选择“item3”时,它应返回item3字段中具有“abc”的所有项目。 我可以为每个item1,2的单独文本框做到这一点..但我只需要一个与所有无线电字段相关联的文本框。
这是相关的html /模板代码。
<form action={% url 'search-fields-radiofields' %} method="get"> <div align="left"> <input type="text" name="name" size="54" /> <br><br> <input type="radio" id="radio1"name="name"> <label for="radio1">item1</label> <input type="radio" id="radio1"name="name"> <label for="radio2">item2</label> <input type="radio" id="radio1"name="name"> <label for="radio3">item3</label> <input type="radio" id="radio1"name="name"> <label for="radio4">item4</label> <input type="radio" id="radio1"name="name"> <label for="radio5">item5</label> <br><br> <input id="search_fields" type="submit" value="Search" size="100"/> </div> </form>
比如,搜索词是'test'。 我选择item5。 返回GetData数据的MultiValueDictKeyError
Variable Value u'name'[u'test', u'on']
。
name
是db中的一个字段,item5应该与它对应。 同样,如果我将文本框名称更改为“item1”,则Get
数据Variable Value u'item1' [u'test', u'on']
我有一个处理所有无线电输入的专用
view
,它适用于与每个项目对应的单个文本框。 但我需要将所有5个单选按钮与上面的1个文本框关联起来。I am not good with front-end and HTML is what I would ideally like to work with here (if I can avoid engaging js/jquery here). I have a single textbox with multiple radio buttons - say, item1, item2,...item5. Each item1, 2... corresponds to a field. When a user enters, say, 'abc' in a textbox and selects 'item3', it should return all items having 'abc' in item3 field. I can do it with individual textboxes for each item1, 2.. but I need just one textbox associated with all the radio fields.
Here's the relevant html/template code.
<form action={% url 'search-fields-radiofields' %} method="get"> <div align="left"> <input type="text" name="name" size="54" /> <br><br> <input type="radio" id="radio1"name="name"> <label for="radio1">item1</label> <input type="radio" id="radio1"name="name"> <label for="radio2">item2</label> <input type="radio" id="radio1"name="name"> <label for="radio3">item3</label> <input type="radio" id="radio1"name="name"> <label for="radio4">item4</label> <input type="radio" id="radio1"name="name"> <label for="radio5">item5</label> <br><br> <input id="search_fields" type="submit" value="Search" size="100"/> </div> </form>
Say, the search term is 'test'. And I select item5. Returns a MultiValueDictKeyError with
Get
data ofVariable Value u'name'[u'test', u'on']
.
name
is one of the fields in the db and item5 is supposed to correspond to it. Similarly, if I change the textbox name to 'item1', thenGet
data isVariable Value u'item1' [u'test', u'on']
I have a dedicated
view
to handle all the radio inputs and it works with individual textboxes corresponding to each of the items. But I need to associate all 5 radio buttons with only 1 textbox as above.
满意答案
根本不需要将按钮与文本框“关联”。
你缺少的是每个单选按钮本身都需要一个
value
。 一旦你完成了,但给了他们一个不同的名字,你就完全了。<input type="text" name="name" size="54" /> <input type="radio" id="radio1" name="field" value="item1"> <label for="radio1">item1</label> <input type="radio" id="radio1" name="field" value="item2"> <label for="radio2">item2</label>
...等等
现在
request.GET
将是{'name': 'test', 'field': 'item1'}
或者其他什么。Thanks all. Solved it from backend myself. The problem was that I was trying to get the request to send just the text value with the key=whatever-radio-is-selected. What I did was looked at the request it was sending which was name=? and textbox=? and then used these two keys to send the right response.
相关问答
更多混合单选按钮和文本框:使用键盘导航的理智方式是什么?(Mixed radio buttons and text boxes: What is the sane way to navigate with a keyboard?)
多个重复项目内的多个单选按钮 - AngularJS(Multiple radio buttons inside multiple repeated items - AngularJS)
在单选按钮上添加一个文本框到BIRT报告参数窗口(Add a textbox against a radio button to BIRT report parameters window)
仅文本单选按钮(Text only radio buttons)
将多个单选按钮与单个文本框关联(Associate multiple radio buttons with a single textbox)
组合框中的VB多个单选按钮(VB Multiple Radio buttons within a group box)
WORD VBA - 单击单选按钮填充文本框(WORD VBA - Radio button click populates textbox)
处理事件到多个单选按钮(handling events to multiple radio buttons)
多个单选按钮ajax发布(Multiple radio buttons ajax post)
如何使用jQuery为某些单选按钮强制使用文本框?(How to make textbox mandatory for certain radio buttons using jQuery?)
相关文章
更多[转]So You Want To Be A Producer
windows phone开发中textbox控件的header属性
Solr4:Tomcat7与Solr之多核配置(Multiple Cores)
A Great List of Windows Tools
Solr: a custom Search RequestHandler
Create a Bootable MicroSD Card
Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
按钮样式
Hadoop 1.2.1 单节点安装(Single Node Setup)步骤
Becoming a data scientist
最新问答
更多Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)
故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)
我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)
TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)
返回嵌套元素的索引(Return index of nested element)
在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)
Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!