Class: NitroRails::NitroFormHelper::NitroFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
NitroRails::NitroOptionsHelper
Defined in:
app/helpers/nitro_rails/nitro_form_helper.rb

Instance Method Summary collapse

Methods included from NitroRails::NitroOptionsHelper

#nitro_defaults, #nitro_options

Instance Method Details

#generate_hidden_attribute_fieldsObject

HIDDEN FIELDS ##



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/helpers/nitro_rails/nitro_form_helper.rb', line 59

def generate_hidden_attribute_fields()
  object_key = @object.class.name.underscore.to_sym
  attributes = {}

  if @object 
    @object.changes.each do |attribute, (old_value, new_value)|
      attributes[attribute] = new_value
    end
  end

  if @options[:params] && @options[:params][object_key]
    attributes.merge!(@options[:params][object_key])
  end

  attributes.map do |attribute, value|
    hidden_attribute_field(attribute, value)
  end.join.html_safe + 
  if @options[:belongs_to]
    hidden_affiliation_field(@options[:belongs_to])
  end
end

#hidden_affiliation_field(affiliation, **options) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'app/helpers/nitro_rails/nitro_form_helper.rb', line 81

def hidden_affiliation_field(affiliation, **options)
  nitro_options(options) do |options|
    options.override(:value, affiliation.id)
    options.default(:data, :nitro_form_target, "field")
    options.concat(:data, :nitro_effects, "addToAffiliatedLists")
    options.override(:data, :nitro_attribute, affiliation.nitro_id(@object.type.pluralize))
  end

  hidden_field("#{affiliation.class.name.underscore}_id", **options)
end

#hidden_attribute_field(attribute, value, **options) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'app/helpers/nitro_rails/nitro_form_helper.rb', line 92

def hidden_attribute_field(attribute, value, **options)
  nitro_options(options) do |options|
    options.override(:value, value)
    options.default(:data, :nitro_form_target, "field")
    options.concat(:data, :nitro_effects, @object.attribute_effects(attribute).join(" ").camelize(:lower))
    options.override(:data, :nitro_attribute, attribute.to_s)
  end
  
  hidden_field(attribute, **options)
end

#submit(text = nil, **options, &block) ⇒ Object

Don’t know if this works.



46
47
48
49
50
51
52
53
# File 'app/helpers/nitro_rails/nitro_form_helper.rb', line 46

def submit(text = nil, **options, &block)
  nitro_options(options) do |options|
    options.default(:class, "btn button_to")
    options.concat(:data, :action, "click->nitro-form#submit")
  end

  super(text, **options, &block)
end

#submit_div(**options, &block) ⇒ Object

SUBMIT ##



36
37
38
39
40
41
42
43
# File 'app/helpers/nitro_rails/nitro_form_helper.rb', line 36

def submit_div(**options, &block)
  nitro_options(options) do |options|
    options.default(:class, "nitro-form-submit")
    options.concat(:data, :action, "click->nitro-form#submit")
  end

  @template.(:div, **options, &block)
end