Class: TestFormWidget

Inherits:
FormWidget show all
Includes:
Cuca::Generator::Markaby
Defined in:
lib/cuca/stdlib/form.rb

Instance Method Summary collapse

Methods included from Cuca::Generator::Markaby

#mab, #mabtext

Methods inherited from FormWidget

#get_variables, #load_variables, #on_submit, #output, #posted?

Methods inherited from Cuca::Widget

#app, #cgi, #clear, clear_hints, #content, #content=, #controller, define_attr_method, #escape, #escapeHTML, #get_assigns, #hints, #initialize, #log, #output, #params, #query_parameters, #request_method, #request_parameters, run_attr_method, #session, #to_s, #unescape, #unescapeHTML

Constructor Details

This class inherits a constructor from Cuca::Widget

Instance Method Details

#formObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cuca/stdlib/form.rb', line 109

def form
  mab { 

     FormErrors(@form_errors)

      form( :action=>@post_to, :method=>'post') { # :name=>@form_name,
 text "This is a demo form, overwrite 'form' method. Enter 'demo'"
        br
 E('demo_input', true) { input(:type => 'text', :value => @demo_input, :name=>'demo_input'); text @error_text }
        br
        br
        input(:type => 'submit', :value => 'save', :name => @submit_name)
       }
  }
end

#make_tipsObject



92
93
94
95
96
97
# File 'lib/cuca/stdlib/form.rb', line 92

def make_tips
  @form_errors.each_pair do |k,v| 
     hints[:tips] ||= []
     hints[:tips] << { :id => k, :title => "Error in form", :text => v}
 end
end

#setupObject



88
89
90
# File 'lib/cuca/stdlib/form.rb', line 88

def setup
  @demo_input = "enter something"
end

#validateObject



100
101
102
103
104
105
106
107
# File 'lib/cuca/stdlib/form.rb', line 100

def validate
  # validate form return true/false
  if @demo_input != 'demo' then
    @form_errors['demo_input'] = "I said please enter 'demo' but you entered #{@demo_input}"
  end
  make_tips
  true
end