Class: Campo::Input
Overview
form << Campo::Input.new( “submit”, :submit )
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#attributes, #attributes The element's html attributes., #fields, #fields The element's child elements.
Attributes included from Childish
Instance Method Summary collapse
-
#initialize(name, type = :text, attributes = {}) ⇒ Input
constructor
A new instance of Input.
Methods inherited from Base
#each, #labelled, #on_output, #output, output, quotable, unhash
Methods included from Convenience
#bit_of_ruby, #checkbox, #fieldset, #hidden, #input, #literal, #password, #radio, #select, #submit, #text, #textarea
Methods included from Iding
Methods included from Childish
Constructor Details
#initialize(name, type = :text, attributes = {}) ⇒ Input
Returns a new instance of Input.
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
# File 'lib/campo/campo.rb', line 634 def initialize( name, type=:text, attributes={} ) id_tag = id_tag( [:text,:hidden,:submit,:password].include?(type) ? nil : attributes[:value] ).gsub(/\W/, "_") name2 = name.gsub(/\[\]/, "") # remove any [] that may have been used for an array like / grouped object atts_name = "#{name2.gsub(/\W/, "_")}#{id_tag}" super( name, { type: type.to_s, id: "#{name2}#{id_tag}", tabindex: %q!#{@campo_tabindex += 1}!, }.merge( attributes ) ) @attributes.delete(:name) if type == :submit @attributes.delete(:tabindex) if type == :hidden self.on_output do |n=0, tab=2| %Q!#{" " * n * tab}%input{ atts[:#{atts_name}], #{Base.unhash( @attributes )} }! end end |