Rails 嵌套属性 ajax / javascript
我正在尝试使用基于 Ryan Bates 教程的 Accepts_nested_attributes_for 方法( http ://railscasts.com/episodes/196-nested-model-form-part-1)。
然而,对于我的表单,我想要一个由子元素组成的选择列表,以便父表单具有子元素列表。然后我想动态添加子项并通过 ajax 将它们填充到选择框。即使表单提交被中止,我也希望创建这些子项。
问题-这可能吗?
谢谢!
编辑:我已经在选择中填充了子项的表单。问题实际上是 ajax 部分是否有效。是否可以只提交表格的一部分?
I am trying to use the accepts_nested_attributes_for method based on the tutorial by Ryan Bates ( http://railscasts.com/episodes/196-nested-model-form-part-1 ).
For my form, however, I want to have a select list made up of the child elements so that the parent form has a list of children. I then want to dynamically add children and populate them to the select box via ajax. I want those children to be created even if the form submit is aborted.
question - is this possible?
thanks!
EDIT: I have the form populating with the children in the select already. The question is really whether the ajax portion will work. Is it possible to submit just a portion of a form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果我最终使用了 jquery 自动完成组合框(http://jqueryui.com/demos/autocomplete/#组合框)并进行了一些修改。具体来说,列出的change:函数会查找无效的选择(如果用户在组合框中键入,这就是我们的情况)。这是小部件的默认代码:
我将其更改为:
不确定是否有更好的方法来做到这一点,但这就是我现在所处的位置!现在正在研究 Rails 中的内容过滤,但那是另一个故事了。
Turns out I ended up using the jquery autocomplete combobox (http://jqueryui.com/demos/autocomplete/#combobox) with some modifications. Specifically, the change: function listed looks for invalid selections (which is our case if the user types into the combobox). Here's the default code from the widget:
and I changed it to:
Not sure if there's a better way to do it, but this is where I'm at now! Now working on the filtering of the content in Rails, but that's another story.