Class: Admin::Base::Resource::FormConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/admin/base/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFormConfig

Returns a new instance of FormConfig.



359
360
361
# File 'lib/admin/base/resource.rb', line 359

def initialize
  @fields_list = []
end

Instance Attribute Details

#fields_listObject (readonly)

Returns the value of attribute fields_list.



357
358
359
# File 'lib/admin/base/resource.rb', line 357

def fields_list
  @fields_list
end

Instance Method Details

#field(name, **options) ⇒ Object



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/admin/base/resource.rb', line 363

def field(name, **options)
  @fields_list << FieldDefinition.new(
    name: name,
    type: options[:type] || :text,
    required: options[:required] || false,
    label: options[:label] || name.to_s.humanize,
    help: options[:help],
    placeholder: options[:placeholder],
    collection: options[:collection],
    create_url: options[:create_url],
    accept: options[:accept],
    rows: options[:rows],
    readonly: options[:readonly] || false,
    if_condition: options[:if],
    unless_condition: options[:unless],
    multiple: options[:multiple] || false,
    creatable: options[:creatable] || false,
    preview: options[:preview] != false,
    variants: options[:variants],
    label_color: options[:label_color],
    label_size: options[:label_size]
  )
end

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



398
399
400
401
402
# File 'lib/admin/base/resource.rb', line 398

def row(**options, &block)
  @fields_list << RowDefinition.new(cols: options[:cols] || 2)
  instance_eval(&block) if block_given?
  @fields_list << RowEnd.new
end

#section(title, **options, &block) ⇒ Object



387
388
389
390
391
392
393
394
395
396
# File 'lib/admin/base/resource.rb', line 387

def section(title, **options, &block)
  @fields_list << SectionDefinition.new(
    title: title,
    description: options[:description],
    collapsible: options[:collapsible] || false,
    collapsed: options[:collapsed] || false
  )
  instance_eval(&block) if block_given?
  @fields_list << SectionEnd.new
end