Class: Conjoin::FormBuilder::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/conjoin/form_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, app, record) ⇒ Input

Returns a new instance of Input.



297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/conjoin/form_builder.rb', line 297

def initialize data, app, record
  @data = data
  @app = app
  @record = record
  @options = {
    name: data.name,
    type: :text,
    id: id,
    value: data.value,
    class: ''
  }.merge! data.options
  options[:class] += ' form-control'
  @options
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



295
296
297
# File 'lib/conjoin/form_builder.rb', line 295

def app
  @app
end

#dataObject

Returns the value of attribute data.



295
296
297
# File 'lib/conjoin/form_builder.rb', line 295

def data
  @data
end

#optionsObject

Returns the value of attribute options.



295
296
297
# File 'lib/conjoin/form_builder.rb', line 295

def options
  @options
end

#recordObject

Returns the value of attribute record.



295
296
297
# File 'lib/conjoin/form_builder.rb', line 295

def record
  @record
end

Instance Method Details

#displayObject



336
337
338
# File 'lib/conjoin/form_builder.rb', line 336

def display
  mab { input options }
end

#errors?Boolean

Returns:

  • (Boolean)


323
324
325
# File 'lib/conjoin/form_builder.rb', line 323

def errors?
  data.errors
end

#idObject



312
313
314
# File 'lib/conjoin/form_builder.rb', line 312

def id
  data.name.gsub(/[^a-z0-9]/, '_').gsub(/__/, '_').gsub(/_$/, '')
end

#nested_nameObject



316
317
318
319
320
321
# File 'lib/conjoin/form_builder.rb', line 316

def nested_name
  # create field names that map to the correct models
  data.names.each_with_index.map do |field, i|
    i != 0 ? "[#{field}]" : field
  end.join
end

#renderObject



327
328
329
330
331
332
333
334
# File 'lib/conjoin/form_builder.rb', line 327

def render
  if options[:type] == :hidden \
  or (options.key?(:wrapper) and options[:wrapper] == false)
    options[:class] = options[:class].gsub(/form-control/, '')
  end

  display
end