Module: Zafu::Process::Forms

Defined in:
lib/zafu/process/forms.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/zafu/process/forms.rb', line 4

def self.included(base)
  base.expander :make_form
end

Instance Method Details

#r_formObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/zafu/process/forms.rb', line 8

def r_form
  options = form_options

  @markup.set_id(options[:id]) if options[:id]
  @markup.set_param(:style, options[:style]) if options[:style]

  if descendant('form_tag')
    # We have a specific place to insert our form
    out expand_with(:form_options => options, :form => self)
  else
    r_form_tag(options)
  end
end

#r_form_tag(options = context[:form_options]) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/zafu/process/forms.rb', line 22

def r_form_tag(options = context[:form_options])
  if options.blank?
    # <form> not in <r:form>, just render all
    markup = Zafu::Markup.new('form')
    @params.each do |k, v|
      markup.set_param(k, v)
    end
  else
    # <form> inside <r:form>
    form_tag(options) do |opts|
      # Render error messages tag
      form_error_messages(opts[:form_helper])

      # Render form elements
      out expand_with(opts)

      # Render hidden fields (these must go after normal elements so that focusFirstElement works)
      hidden_fields = form_hidden_fields(options)
      out "<div class='hidden'>"
      hidden_fields.each do |k,v|
        if v.kind_of?(String)
          v = "'#{v}'" unless v.kind_of?(String) && ['"', "'"].include?(v[0..0])
          out "<input type='hidden' name='#{k}' value=#{v}/>"
        else
          # We use ['ffff'] to indicate that the content is already escaped and ready for ERB.
          out v.first
        end
      end
      out '</div>'

      # What is this ?
      #@blocks = opts[:blocks_bak] if opts[:blocks_bak]
    end
  end
end