Class: BulmaPhlex::Rails::NestedFormDeleteButton

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

Overview

# Nested Form Delete Button Component

This button can be added to a nested form row to allow users to remove the row. It uses the Stimulus controller NestedFormsDeleteRow to handle the deletion logic.

#### Arguments

  • ‘row_selector`: String - A CSS selector that identifies the row to be deleted. This is passed to the element’s ‘closest` method to find the row element.

  • ‘action`: String - The action to perform when the button is clicked. This should correspond to a method in the NestedFormsDeleteRow Stimulus controller. Either “remove” to remove the row from the DOM, or “markForDestruction” to mark the row for destruction (for existing records).

  • ‘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(row_selector:, action:, label: nil, icon_left: nil, icon_right: nil, **html_attributes) ⇒ NestedFormDeleteButton

rubocop:disable Metrics/ParameterLists



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bulma_phlex/rails/components/nested_form_delete_button.rb', line 21

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

Instance Method Details

#view_templateObject



35
36
37
38
39
# File 'lib/bulma_phlex/rails/components/nested_form_delete_button.rb', line 35

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