Class: Conjoin::FormBuilder::Input
- Inherits:
-
Object
- Object
- Conjoin::FormBuilder::Input
- Defined in:
- lib/conjoin/form_builder.rb
Direct Known Subclasses
CheckboxInput, DateInput, DatetimeInput, DecimalInput, DisplayInput, FileInput, HiddenInput, IntegerInput, PasswordInput, RadioInput, SelectInput, StringInput, TextInput, TimeInput
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#data ⇒ Object
Returns the value of attribute data.
-
#options ⇒ Object
Returns the value of attribute options.
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
- #display ⇒ Object
- #errors? ⇒ Boolean
- #id ⇒ Object
-
#initialize(data, app, record) ⇒ Input
constructor
A new instance of Input.
- #nested_name ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(data, app, record) ⇒ Input
Returns a new instance of Input.
302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/conjoin/form_builder.rb', line 302 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. [:class] += ' form-control' @options end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
300 301 302 |
# File 'lib/conjoin/form_builder.rb', line 300 def app @app end |
#data ⇒ Object
Returns the value of attribute data.
300 301 302 |
# File 'lib/conjoin/form_builder.rb', line 300 def data @data end |
#options ⇒ Object
Returns the value of attribute options.
300 301 302 |
# File 'lib/conjoin/form_builder.rb', line 300 def @options end |
#record ⇒ Object
Returns the value of attribute record.
300 301 302 |
# File 'lib/conjoin/form_builder.rb', line 300 def record @record end |
Instance Method Details
#display ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/conjoin/form_builder.rb', line 341 def display = .delete :append_button if mab do div class: 'input-group' do input div class: 'input-group-btn' do class: 'btn btn-primary', type: [:type] || 'button', 'on-click-get' => [:href] do text [:text] end end end end else mab { input } end end |
#errors? ⇒ Boolean
328 329 330 |
# File 'lib/conjoin/form_builder.rb', line 328 def errors? data.errors end |
#id ⇒ Object
317 318 319 |
# File 'lib/conjoin/form_builder.rb', line 317 def id data.name.gsub(/[^a-z0-9]/, '_').gsub(/__/, '_').gsub(/_$/, '') end |
#nested_name ⇒ Object
321 322 323 324 325 326 |
# File 'lib/conjoin/form_builder.rb', line 321 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 |
#render ⇒ Object
332 333 334 335 336 337 338 339 |
# File 'lib/conjoin/form_builder.rb', line 332 def render if [:type] == :hidden \ or (.key?(:wrapper) and [:wrapper] == false) [:class] = [:class].gsub(/form-control/, '') end display end |