Class: BulmaPhlex::Rails::NestedFormAddButton

Inherits:
Base
  • Object
show all
Defined in:
lib/bulma_phlex/rails/components/nested_form_add_button.rb

Overview

# Nested Form Add Button Component

This button can be added to a form to allow users to dynamically add new nested form rows. It uses the Stimulus controller NestedFormsAddRow to handle the addition logic.

#### Arguments

  • ‘template_id`: String - The ID of the `<template>` element that contains the nested form fields to be added.

  • ‘container_selector`: String - A CSS selector that identifies the container element where new rows should be added.

  • ‘label`: String (optional) - The text label to display on the button.

  • ‘icon_left`: String (optional) - The name of an icon to display on the left side of the button.

  • ‘icon_right`: String (optional) - The name of an icon to display on the right side of the button.

Instance Method Summary collapse

Constructor Details

#initialize(template_id:, container_selector:, label: nil, icon_left: nil, icon_right: nil, **html_attributes) ⇒ NestedFormAddButton

rubocop:disable Metrics/ParameterLists



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bulma_phlex/rails/components/nested_form_add_button.rb', line 19

def initialize(template_id:, # rubocop:disable Metrics/ParameterLists
               container_selector:,
               label: nil,
               icon_left: nil,
               icon_right: nil,
               **html_attributes)
  @template_id = template_id
  @label = label
  @icon_left = icon_left
  @icon_right = icon_right
  @container_selector = container_selector
  @html_attributes = html_attributes
end

Instance Method Details

#view_templateObject



33
34
35
36
37
# File 'lib/bulma_phlex/rails/components/nested_form_add_button.rb', line 33

def view_template
  render BulmaPhlex::FormField.new do
    BulmaPhlex::Button(@label, icon_left: @icon_left, icon_right: @icon_right, **button_html_attributes)
  end
end