Sha256: 4ca9cd3b5e564c9184d15ea6665b4c508674f7c7cf63d3bfd1158da36bf34caf

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module Capybara
  module ActiveAdmin
    module Selectors
      module Form
        # @param name [String] form model name
        def form_selector(name)
          "form.formtastic.#{name}"
        end

        def label_selector
          'label.label'
        end

        def inline_error_selector
          'p.inline-errors'
        end

        def semantic_error_selector
          'ul.errors > li'
        end

        def has_many_fields_selector(association_name)
          "div.has_many_container.#{association_name} > fieldset.inputs.has_many_fields"
        end

        def form_submit_selector(value = nil)
          selector = %(input[type="submit"])
          selector += %([value="#{value}"]) unless value.nil?
          selector
        end

        def input_selector(label, options)
          text = options.delete(:text)
          type = options.delete(:type) || :text

          label_opts = options.merge(text: label)
          label = find(label_selector, label_opts)

          input_id = label[:for]
          tag_name = type.to_sym == :select ? 'select' : 'input'
          selector = "#{tag_name}##{input_id}"
          selector = %(#{selector}[value="#{text}"]) unless text.nil?
          selector
        end

        def input_container_selector(label, exact: nil)
          return 'li' if label.nil?

          label_opts = Util.options_with_text(label, exact: exact)
          label_node = find(label_selector, label_opts)
          li_id = label_node.ancestor('li')[:id]
          "li##{li_id}"
        end

        def filter_form_selector
          '.filter_form'
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capybara_active_admin-0.3.0 lib/capybara/active_admin/selectors/form.rb