Class: DrgcmsFormFields::Comment
- Inherits:
-
DrgcmsField
- Object
- DrgcmsField
- DrgcmsFormFields::Comment
- Defined in:
- app/models/drgcms_form_fields/comment.rb
Overview
Implementation of comment DRG CMS form field. Comments may also be written on the place of form field.
Form options:
-
text:
any text. Text will be translated if key is found in translations. (required) -
type:
comment (required) -
caption:
Caption text written in label place. If set to false comment
will occupy whole row. (required)
-
html:
Optional html attributes will be added to div surrounding the comment.
Form example:
30:
type: comment
text: myapp.comment_text
caption: false
html:
style: 'color: red'
class: some_class
id: some_id
Instance Attribute Summary
Attributes inherited from DrgcmsField
Instance Method Summary collapse
-
#render ⇒ Object
Render comment field html code.
Methods inherited from DrgcmsField
#__css_code, get_data, #hash_to_options, #html, #initialize, #record_text_for, #ro_standard, #set_css_code, #set_default_value, #set_initial_value, #set_style, #t
Constructor Details
This class inherits a constructor from DrgcmsFormFields::DrgcmsField
Instance Method Details
#render ⇒ Object
Render comment field html code
51 52 53 54 55 56 57 58 59 |
# File 'app/models/drgcms_form_fields/comment.rb', line 51 def render comment = @yaml['comment'] || @yaml['text'] @yaml['html'] ||= {} @yaml['html']['class'] = 'dc-comment ' + @yaml['html']['class'].to_s html = @yaml['html'].inject('') { |r, e| r << %( #{e[0]}="#{e[1]}") } @html << %(<div #{html}>#{t(comment, comment).gsub("\n",'<br>')}</div>) self end |