Class: Objs::Form
- Inherits:
-
Gloo::Core::Obj
- Object
- Gloo::Core::Obj
- Objs::Form
- Defined in:
- lib/objs/form.rb
Constant Summary collapse
- KEYWORD =
'form'.freeze
- KEYWORD_SHORT =
'form'.freeze
- NAME =
Form
'name'.freeze
- ID =
'id'.freeze
- METHOD =
'method'.freeze
- METHOD_DEFAULT =
'post'.freeze
- ACTION =
'action'.freeze
- CANCEL_PATH =
'cancel_path'.freeze
- CONTENT =
'content'.freeze
- STYLES =
'styles'.freeze
Class Method Summary collapse
-
.doc_data ⇒ Object
Get the object's documentation data.
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#action_value ⇒ Object
Get the action for the form.
-
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
-
#add_default_children ⇒ Object
Add children to this object.
-
#cancel_button_styles ⇒ Object
Get the cancel button styles.
-
#cancel_path_value ⇒ Object
Get the cancel path for the form.
-
#close_form ⇒ Object
Close the form.
-
#form_content ⇒ Object
Get all the form content, the collection of form fields.
-
#form_styles ⇒ Object
Get the form styles.
-
#method_value ⇒ Object
Get the method for the form.
-
#msg_render ⇒ Object
Render the form and all contained fields.
-
#name_value ⇒ Object
Get the name for the form.
-
#open_form ⇒ Object
Open the form.
-
#render ⇒ Object
Render the Form as HTML.
-
#render_content ⇒ Object
Render the element content using the specified render function.
-
#render_thing(e) ⇒ Object
Render a string or other object.
-
#styles ⇒ Object
Get the styles for the form.
-
#submit_button_styles ⇒ Object
Get the submit button styles.
Class Method Details
.doc_data ⇒ Object
Get the object's documentation data.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/objs/form.rb', line 275 def self.doc_data { :name => KEYWORD, :shortcut => KEYWORD_SHORT, :description => 'An HTML form. Contains a collection of form fields.', :children => [ 'name (string) — The name of the form, used for both the name and the id of the form element.', 'action (string) — The URL to which the form is submitted.', "method (string) — Optional, default 'post'. The HTTP method used to submit the form.", 'cancel_path (string) — The URL to which the form is submitted when the cancel button is clicked.', 'styles (container) — Container of style classes for the form. Children: actions_div, submit, cancel, field_group, field_label, field_control.', 'content (container) — The collection of form fields. Other elements can also be included here, for formatting or extra buttons.' ], :messages => [ 'render — Manually render the HTML form. Normally the render is called by the web server when the page containing the element is requested.' ], :examples => <<~EXAMPLES.strip page [can] : messages [can] : new [page] : head [e] : content [can] : title [e] : New Message body [e] : content [can] : nav [alias] : shared.nav h2 [e] : New Message f [form] : name [string] : message_form action [string] : /messages method [string] : post cancel_path [string] : /messages styles [alias] : form_styles content [can] : id [field] : type [string] : hidden value [string] : 13 message [field] : type [string] : text autofocus [boolean] : true placeholder [string] : the message goes here… … EXAMPLES } end |
.messages ⇒ Object
Get a list of message names that this object receives.
167 168 169 |
# File 'lib/objs/form.rb', line 167 def self. return super + [ 'render' ] end |
.short_typename ⇒ Object
The short name of the object type.
36 37 38 |
# File 'lib/objs/form.rb', line 36 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
29 30 31 |
# File 'lib/objs/form.rb', line 29 def self.typename return KEYWORD end |
Instance Method Details
#action_value ⇒ Object
Get the action for the form. This is the path to POST to, for example.
63 64 65 66 67 |
# File 'lib/objs/form.rb', line 63 def action_value o = find_child ACTION o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o ? o.value : nil end |
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
138 139 140 |
# File 'lib/objs/form.rb', line 138 def add_children_on_create? return true end |
#add_default_children ⇒ Object
Add children to this object. This is used by containers to add children needed for default configurations.
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/objs/form.rb', line 147 def add_default_children fac = @engine.factory # Create attributes with ID and Classes fac.create_string NAME, '', self fac.create_string METHOD, 'post', self fac.create_string ACTION, '', self fac.create_string CANCEL_PATH, '', self fac.create_can CONTENT, self end |
#cancel_button_styles ⇒ Object
Get the cancel button styles.
124 125 126 |
# File 'lib/objs/form.rb', line 124 def return @styles['cancel'] || '' end |
#cancel_path_value ⇒ Object
Get the cancel path for the form.
72 73 74 75 76 |
# File 'lib/objs/form.rb', line 72 def cancel_path_value o = find_child CANCEL_PATH o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o ? o.value : nil end |
#close_form ⇒ Object
Close the form.
220 221 222 |
# File 'lib/objs/form.rb', line 220 def close_form return "</form>" end |
#form_content ⇒ Object
Get all the form content, the collection of form fields.
81 82 83 84 85 |
# File 'lib/objs/form.rb', line 81 def form_content o = find_child CONTENT o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o end |
#form_styles ⇒ Object
Get the form styles. Use the name if none is provided.
110 111 112 |
# File 'lib/objs/form.rb', line 110 def form_styles return @styles['form'] || name_value end |
#method_value ⇒ Object
Get the method for the form. 'post' is the default.
53 54 55 56 57 |
# File 'lib/objs/form.rb', line 53 def method_value o = find_child METHOD o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o.value || METHOD_DEFAULT end |
#msg_render ⇒ Object
Render the form and all contained fields.
174 175 176 177 178 |
# File 'lib/objs/form.rb', line 174 def msg_render content = self.render @engine.heap.it.set_to content return content end |
#name_value ⇒ Object
Get the name for the form.
43 44 45 46 47 |
# File 'lib/objs/form.rb', line 43 def name_value o = find_child NAME o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o ? o.value : nil end |
#open_form ⇒ Object
Open the form.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/objs/form.rb', line 188 def open_form name = name_value = "" if cancel_path_value = <<~HTML <a class="#{}" href="#{cancel_path_value}"> Cancel</a> HTML end return <<~HTML <form class='#{form_styles}' id='#{name}' method='#{method_value}' action='#{action_value}' accept-charset='UTF-8'> <div class="actions"> <input type="submit" name="commit" value="Save" class="#{}" data-disable-with="Saving..." /> #{} </div> HTML end |
#render ⇒ Object
Render the Form as HTML.
227 228 229 230 |
# File 'lib/objs/form.rb', line 227 def render @styles = styles return open_form + render_content + close_form end |
#render_content ⇒ Object
Render the element content using the specified render function. This is a recursive function (through one of the other render functions).
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/objs/form.rb', line 236 def render_content fields = "" field_can = form_content return "" if field_can.nil? field_can.children.each do |o| o = Gloo::Objs::Alias.resolve_alias( @engine, o ) if o.class == Field fields << o.render( @styles ) elsif o.class == Element fields << o.render_html elsif o data = render_thing o ( fields << data ) if data end end return fields end |
#render_thing(e) ⇒ Object
Render a string or other object.
259 260 261 262 263 264 265 266 |
# File 'lib/objs/form.rb', line 259 def render_thing e begin return e.render( 'render_html' ) rescue => e @engine.log_exception e return '' end end |
#styles ⇒ Object
Get the styles for the form. Retuns styles in the form of a hash: { 'field_group' => 'form-group mt-3', … }
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/objs/form.rb', line 92 def styles style_h = {} o = find_child STYLES return style_h unless o o = Gloo::Objs::Alias.resolve_alias( @engine, o ) o.children.each do |c| style_h[ c.name ] = c.value end # puts "styles: #{style_h}" return style_h end |
#submit_button_styles ⇒ Object
Get the submit button styles.
117 118 119 |
# File 'lib/objs/form.rb', line 117 def return @styles['submit'] || '' end |