我有这样的输入:
<%= f.input :email %>表单(v3.1.5)和rails(v4.2)的输出如下所示。
<li class="email input required stringish" id="applicant_email_input">
<label for="applicant_email" class="label">Email<abbr title="required">*</abbr></label>
<input maxlength="255" id="applicant_email" type="email" value="davedave@gmail.com" name="applicant[email]">
</li>我真正想要的是让表单发出:
<div class="email input required stringish form-group" id="applicant_email_input">
<label for="applicant_email" class=" control-label">Email<abbr title="required">*</abbr></label>
<span class="form-wrapper">
<input maxlength="255" id="applicant_email" type="email" value="davedave@gmail.com" name="applicant[email]" class="form-control">
</span>
</div>这就是这个应用程序所传递的表单(v2.3.1)和(v3.0.0)和rails(v4.1)的内容。
我很想把创业板包括进来,然后把旧的行为拿回来,但就像我所知道的,在Fortastic3的时候就退出了。
现在我有了一个应用程序,有几千个呼叫f.input,我需要按摩来自表单的输出。最好的方法是什么?
发布于 2017-10-04 19:03:45
这里有一个被黑客攻击的formtastic版本,我已经命名为boomtastic,它可以做您想做的事情。
(这实际上包括了除form-wrapper之外所需的所有内容。然而,form-wrapper似乎只是bootstrap-formtastic的一个元素,而不是formtastic或标准bootstrap的一部分。如果您真的想拥有<span class="form-wrapper">,我认为您可以通过编辑boomtastic/lib/formtastic/inputs/base/wrapping.rb来添加这个功能。)
发布于 2017-09-25 20:59:53
也许你可以使用表单的自定义输入?此外,这些链接可能会有所帮助:helper.rb和https://github.com/justinfrench/formtastic/issues/625。
特别是,Justin French建议您在config/initializers/formtasticpatches.rb中给应用程序添加一个初始化程序,它看起来如下所示:
module Formtastic
module Inputs
module Base
module Wrapping
def input_wrapping(&block)
template.content_tag(:li,
[template.capture(&block), error_html, hint_html].join("\n").html_safe,
wrapper_html_options
)
end
end
end
end
end然后将:li改为a :div。
发布于 2017-09-19 08:28:22
使用jquery在页面重新加载时更改表单的解决方案如何?
var ready = function () {
var $input = $('#applicant_email');
var input_html = $input.html();
$input.html('<span class="form-wrapper">' + input_html + '</span>');
}
$(document).on('turbolinks:load', ready);您需要告诉我如何选择这些字段,因为在您的示例中,您没有包含完整的html和对实际问题的任何解释。
我还看到其他div还有一些其他类,这可以用一些简单的jquery来完成。
否则,您可以编辑该宝石。
https://stackoverflow.com/questions/46229440
复制相似问题