【问题标题】:Switch between a text field and label在文本字段和标签之间切换
【发布时间】:2018-04-20 21:10:43
【问题描述】:

我对 Rails 比较陌生。我有以下image。

我想要一个文本字段来在单击更新按钮时替换数字,并保持之前的数字,显示的按钮更改为确认。

我的应用程序中有以下内容。

%tr[fund_flow]
  %td= fund_flow.symbol
  %td= fund_flow.trade_date
  %td= number_to_currency(fund_flow.nav, unit: '')
  %td= number_to_currency(fund_flow.shares_outstanding, unit: '')
  %td= label_tag("N/A", number_to_currency(fund_flow.fund_flow, unit: ''), {style: "#{'display:show' if flag}"})
  %td
    = form_tag(update_nav_history_path(fund_flow.id), method: "post") do
      = text_field_tag("update", nil, {style: "#{'display:none' if !flag}"})
      = submit_tag("Update")

以下内容帮助我走到了这一步。 solution

不确定如何设置全局标志变量并更改设置标志时发生的情况。

【问题讨论】:

    标签: ruby-on-rails forms ruby-on-rails-4


    【解决方案1】:

    有红宝石可以完全按照您的意愿处理。特别是我正在使用 best_in_place。这允许创建显示为标签的字段,但如果您单击它们或单击按钮,则会变成输入字段。

    输入字段可以包含确认或取消更改的按钮(或仅响应 esc 或 enter 键,或在字段外单击)。更改值后,它调用方法来更新对象并触发回调,您可以在其中显示确认消息。您还可以执行验证并显示错误消息。

    https://github.com/bernat/best_in_place

    一些图片:

    它还处理选择框:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      相关资源
      最近更新 更多