【问题标题】:Simple_Form Auto Disabling Inputs on ReloadSimple_Form 重新加载时自动禁用输入
【发布时间】:2021-04-27 21:36:08
【问题描述】:

更新 simple_form 工作正常,但是当我重新加载页面时,它会将所有输入呈现为禁用。有任何想法吗?我在文档中找不到任何说明是什么原因导致它自动执行此操作的。谢谢

简单的形式。

<%= simple_form_for @product_campaign, url: update_completion_criteria_rules_partner_product_product_campaign_path(partner_id: @partner.id, product_id: @product.id, id: @product_campaign.id), remote: true, html: { id: "product-campaign-completion-criteria-rules"} do |f| %>
  <div class="">
    <%= f.simple_fields_for :completion_criteria_rules, f.object.completion_criteria_rules.order(:created_at) do |complete_criteria_rule| %>
      <%= render 'completion_criteria_rule_fields', :f => complete_criteria_rule %>
    <% end %>
    <%= link_to_add_association "Add Completion Criteria Rule", f, :completion_criteria_rules, class: "btn btn-info float-left mt-10", id: "add-completion-criteria-rule", data: { } %>
    <button type="submit" class="btn btn-info float-right mt-10" id="update-product-campaign-form" ><span id="save-journey-button-text">Save Changes</span></button>
  </div>
<% end %>

completion_criteria_rule_fields 部分

  <div class="form-row">
    <div class="form-group col-md-6">
      <%= f.input :events, collection: CompletionCriteriaRule::EVENTS_OPTIONS, label: 'Choose Events', include_blank: false, input_html: { class: "form-control form-field-type", "data-provide": "selectpicker", multiple: true } %>
    </div>
    <div class="form-group col-md-6">
      <%= f.input :actions, collection: [['Add Campaign', 'add_campaign']], label: 'Choose Action', input_html: { class: "form-control form-field-type actions-dropdown", "data-provide": "selectpicker", multiple: true } %>
    </div>
  </div>
  <div class="form-row add-campaign-dropdown-wrapper" <% unless f.object.actions&.include?('add_campaign') %>style="display:none;<% end %>">
    <div class="form-group col-md-6">
      <%= f.input :transition_campaign_id, collection: @product_campaign.product.product_campaigns.where.not(id: @product_campaign.id).published.map{|k,v| [k.name.titleize, k.id]}, label: 'Select Campaign To Add', input_html: { class: "form-control form-field-type", "data-provide": "selectpicker" } %>
    </div>
    <div class="form-group col-md-6">
      <label>Campaign Start Delay</label>
      <div class="input-group">
        <%= f.input_field :transition_campaign_delay, class: "form-control form-field-type" %>
        <span class="input-group-addon">days</span>
      </div>
    </div>
  </div>
  <div class="form-row">
    <div class="form-group col-md-12">
      <span class="float-right">
      <%= link_to_remove_association 'Remove Rule', f, class: "btn btn-danger btn-xs" %><br>
    </span>
    </div>
  </div>
  <div class="divider"></div>
</div>

completion_criteria_rule.rb

class CompletionCriteriaRule < ApplicationRecord
  EVENTS_OPTIONS = [["Appointment Booked", "appointment.booked"], ["Appointment Attended", "appointment.attended"], ["Appointment Cancelled", "appointment.cancelled"], ["Lifecycle Changed to Client", "lifecycle.client"], ["Lifecycle Changed to Lead", "lifecycle.lead"], ["Lifecycle Changed to Former Client", "lifecycle.former_client"], ["Lifecycle Changed to None", "lifecycle.none"]].freeze

  belongs_to :product_campaign
  belongs_to :transition_campaign, class_name: 'ProductCampaign', foreign_key: 'transition_campaign_id', optional: true

  validates :product_campaign, :events, :actions, presence: true
  validates :transition_campaign, :transition_campaign_delay, presence: true, if: -> { actions&.include? 'add_campaign' }

  before_save :reject_blank_events
  before_save :reject_blank_actions

  def reject_blank_events
    events.reject!(&:blank?)
  end

  def reject_blank_actions
    actions.reject!(&:blank?)
  end
end

【问题讨论】:

    标签: ruby-on-rails simple-form


    【解决方案1】:

    发现我有一些 js 正在禁用表单输入,而某个类在页面加载后禁用了输入。现在一切正常。

    【讨论】:

      猜你喜欢
      • 2021-04-24
      • 1970-01-01
      • 2013-05-23
      • 2014-10-14
      • 1970-01-01
      • 1970-01-01
      • 2012-01-17
      • 1970-01-01
      • 2017-12-05
      相关资源
      最近更新 更多