Class: Waw::Routing::FormValidationFeedback
- Inherits:
-
RoutingRule
- Object
- RoutingRule
- Waw::Routing::FormValidationFeedback
- Defined in:
- lib/waw/routing/form_validation_feedback.rb
Overview
FormValidationFeedback routing
Instance Method Summary collapse
- #generate_js_code(result, align = 0) ⇒ Object
-
#initialize(opts = {}) ⇒ FormValidationFeedback
constructor
A new instance of FormValidationFeedback.
Methods inherited from RoutingRule
Constructor Details
#initialize(opts = {}) ⇒ FormValidationFeedback
Returns a new instance of FormValidationFeedback.
6 7 8 |
# File 'lib/waw/routing/form_validation_feedback.rb', line 6 def initialize(opts = {}) @options = opts end |
Instance Method Details
#generate_js_code(result, align = 0) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/waw/routing/form_validation_feedback.rb', line 10 def generate_js_code(result, align=0) buffer = "" buffer << " "*align + "str = '';\n" buffer << " "*align + "str += '<ul>';\n" buffer << " "*align + "for (var k in data[1]) {\n" buffer << " "*(align+2) + "str += '<li>' + messages[data[1][k]] + '</li>';\n" buffer << " "*align + "}\n" buffer << " "*align + "str += '</ul>';\n" buffer << " "*align + "$(form + ' .feedback').show();\n" buffer << " "*align + "$(form + ' .feedback').html(str);\n" if @options[:scroll] where = case @options[:scroll] when :top '0' when :form "$(form).offset().top" when :feedback "$(form + ' .feedback').offset().top" end buffer << "$('html, body').animate( { scrollTop: #{where} }, 'slow' );\n" end buffer end |