Module: Bureaucrat::Quickfields

Includes:
Fields
Defined in:
lib/bureaucrat/quickfields.rb

Overview

Shortcuts for declaring form fields

Instance Method Summary collapse

Instance Method Details

#boolean(name, options = {}) ⇒ Object

Declare a BooleanField



58
59
60
# File 'lib/bureaucrat/quickfields.rb', line 58

def boolean(name, options = {})
  field name, BooleanField.new(options)
end

#checkbox_multiple_choice(name, choices = [], options = {}) ⇒ Object

Declare a MultipleChoiceField with the CheckboxSelectMultiple widget



88
89
90
# File 'lib/bureaucrat/quickfields.rb', line 88

def checkbox_multiple_choice(name, choices = [], options = {})
  field name, MultipleChoiceField.new(choices, options.merge(widget: Widgets::CheckboxSelectMultiple.new))
end

#choice(name, choices = [], options = {}) ⇒ Object

Declare a ChoiceField with choices



68
69
70
# File 'lib/bureaucrat/quickfields.rb', line 68

def choice(name, choices = [], options = {})
  field name, ChoiceField.new(choices, options)
end

#decimal(name, options = {}) ⇒ Object

Declare a BigDecimalField



38
39
40
# File 'lib/bureaucrat/quickfields.rb', line 38

def decimal(name, options = {})
  field name, BigDecimalField.new(options)
end

#delete(name) ⇒ Object

Delete field named name



13
14
15
# File 'lib/bureaucrat/quickfields.rb', line 13

def delete(name)
  base_fields.delete name
end

#email(name, options = {}) ⇒ Object

Declare an EmailField



48
49
50
# File 'lib/bureaucrat/quickfields.rb', line 48

def email(name, options = {})
  field name, EmailField.new(options)
end

#file(name, options = {}) ⇒ Object

Declare a FileField



53
54
55
# File 'lib/bureaucrat/quickfields.rb', line 53

def file(name, options = {})
  field name, FileField.new(options)
end

#hide(name) ⇒ Object

Hide field named name



7
8
9
10
# File 'lib/bureaucrat/quickfields.rb', line 7

def hide(name)
  base_fields[name] = base_fields[name].dup
  base_fields[name].widget = Widgets::HiddenInput.new
end

#integer(name, options = {}) ⇒ Object

Declare an IntegerField



33
34
35
# File 'lib/bureaucrat/quickfields.rb', line 33

def integer(name, options = {})
  field name, IntegerField.new(options)
end

#multiple_choice(name, choices = [], options = {}) ⇒ Object

Declare a MultipleChoiceField with choices



78
79
80
# File 'lib/bureaucrat/quickfields.rb', line 78

def multiple_choice(name, choices = [], options = {})
  field name, MultipleChoiceField.new(choices, options)
end

#null_boolean(name, options = {}) ⇒ Object

Declare a NullBooleanField



63
64
65
# File 'lib/bureaucrat/quickfields.rb', line 63

def null_boolean(name, options = {})
  field name, NullBooleanField.new(options)
end

#password(name, options = {}) ⇒ Object

Declare a CharField with password widget



28
29
30
# File 'lib/bureaucrat/quickfields.rb', line 28

def password(name, options = {})
  field name, CharField.new(options.merge(widget: Widgets::PasswordInput.new))
end

#radio_choice(name, choices = [], options = {}) ⇒ Object

Declare a ChoiceField using the RadioSelect widget



83
84
85
# File 'lib/bureaucrat/quickfields.rb', line 83

def radio_choice(name, choices = [], options = {})
  field name, ChoiceField.new(choices, options.merge(widget: Widgets::RadioSelect.new))
end

#regex(name, regexp, options = {}) ⇒ Object

Declare a RegexField



43
44
45
# File 'lib/bureaucrat/quickfields.rb', line 43

def regex(name, regexp, options = {})
  field name, RegexField.new(regexp, options)
end

#string(name, options = {}) ⇒ Object

Declare a CharField with text input widget



18
19
20
# File 'lib/bureaucrat/quickfields.rb', line 18

def string(name, options = {})
  field name, CharField.new(options)
end

#text(name, options = {}) ⇒ Object

Declare a CharField with text area widget



23
24
25
# File 'lib/bureaucrat/quickfields.rb', line 23

def text(name, options = {})
  field name, CharField.new(options.merge(widget: Widgets::Textarea.new))
end

#typed_choice(name, choices = [], options = {}) ⇒ Object

Declare a TypedChoiceField with choices



73
74
75
# File 'lib/bureaucrat/quickfields.rb', line 73

def typed_choice(name, choices = [], options = {})
  field name, TypedChoiceField.new(choices, options)
end