Garlic.js动态生成的字段 [英] Garlic.js on dynamically generated fields

查看:65
本文介绍了Garlic.js动态生成的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 garlic.js 处理使用Javascript动态生成的字段,例如此Railscast 或使用 Cocoon ?我已经尝试在嵌套字段中明确地包含js文件,但没有运气:

How can I get garlic.js to work on fields generated dynamically with Javascript, for instance like in this Railscast or by using Cocoon? I have tried explicitly including the js file in the nested fields partial, but no luck:

= javascript_include_tag 'garlic'
.nested-fields
  = f.inputs do
    = f.input :client_id #etc


推荐答案

我如何使用jquery存储api: https://github.com/julien-maurel/jQuery-Storage-API 除了调用大蒜以保存表单状态外,还要保留动态生成表单的HTML。

How I got around this was using the jquery storage api: https://github.com/julien-maurel/jQuery-Storage-API to persist the HTML of the dynamically generated form in addition to invoking garlic to save the form state.

页面加载后,我会检查localstorage中是否存在持久化表单。如果是,则将html加载到表单元素中,然后调用garlic恢复表单状态!

Upon page load, I check if the persisted form exists in localstorage. If it does, then load the html into the form element, then call garlic to restore form state!

这篇关于Garlic.js动态生成的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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