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
21
22
23
24
25
26
# File 'lib/zafu/process/forms.rb', line 8

def r_form
  unless @params[:on].nil? || @params[:on].split(',').include?(@context[:ajax_action])
    return ''
  end

  return parser_error('Cannot render update form in list context.') if node.list_context?

  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, :form_prefix => dom_name)
  else
    r_form_tag(options)
  end
end

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/zafu/process/forms.rb', line 28

def r_form_tag(options = context[:form_options])
  form_tag(options) do |opts|
    # Render error messages tag
    form_error_messages(opts[:form_helper])

    # Render form elements
    out expand_with(opts.merge(:form_prefix => dom_name))

    # 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}/>"
      elsif v.kind_of?(Array)
        # We use ['ffff'] to indicate that the content is already escaped and ready for ERB.
        out v.first
      end
    end
    out '</div>'
  end
end