Class: Jabber::Dataforms::XDataField

Class | Jabber::Dataforms::XDataField
In: | lib/xmpp4r/dataforms/x/data.rb
Parent: | XMPPElement

Child of XData, contains configurable/configured options of this Data Form

### Methods

label label= new options options= required= required? type type= value value= values values= var var=

### Public Class methods

new(var=nil, type=nil)

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 148
    148:       def initialize(var=nil, type=nil)
    149:         super()
    150:         self.var = var
    151:         self.type = type
    152:       end

### Public Instance methods

label()

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 154
    154:       def label
    155:         attributes['label']
    156:       end

label=(s)

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 158
    158:       def label=(s)
    159:         attributes['label'] = s
    160:       end

options()

Get the options (in a Data Form with type=‘form’)

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 269
    269:       def options
    270:         res = {}
    271:         each_element('option') { |e|
    272:           value = nil
    273:           e.each_element('value') { |ve| value = ve.text }
    274:           res[value] = e.attributes['label']
    275:         }
    276:         res
    277:       end

options=(hsh)

Set the options

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 281
    281:       def options=(hsh)
    282:         delete_elements('option')
    283:         hsh.each { |value,label|
    284:           o = add(REXML::Element.new('option'))
    285:           o.attributes['label'] = label
    286:           o.add(REXML::Element.new('value')).text = value
    287:         }
    288:       end

required=(r)

Set if this field is required

r: | [true] or [false]

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 229
    229:       def required=(r)
    230:         delete_elements('required')
    231:         if r
    232:           add REXML::Element.new('required')
    233:         end
    234:       end

required?()

Is this field required (has the <required/> child)?

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 220
    220:       def required?
    221:         res = false
    222:         each_element('required') { res = true }
    223:         res
    224:       end

type()

Type of this field

result: | * :boolean :fixed :hidden :jid_multi :jid_single :list_multi :list_single :text_multi :text_private :text_single nil

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 184
    184:       def type
    185:         case attributes['type']
    186:           when 'boolean' then :boolean
    187:           when 'fixed' then :fixed
    188:           when 'hidden' then :hidden
    189:           when 'jid-multi' then :jid_multi
    190:           when 'jid-single' then :jid_single
    191:           when 'list-multi' then :list_multi
    192:           when 'list-single' then :list_single
    193:           when 'text-multi' then :text_multi
    194:           when 'text-private' then :text_private
    195:           when 'text-single' then :text_single
    196:           else nil
    197:         end
    198:       end

type=(t)

Set the type of this field (see type)

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 202
    202:       def type=(t)
    203:         case t
    204:           when :boolean then attributes['type'] = 'boolean'
    205:           when :fixed then attributes['type'] = 'fixed'
    206:           when :hidden then attributes['type'] = 'hidden'
    207:           when :jid_multi then attributes['type'] = 'jid-multi'
    208:           when :jid_single then attributes['type'] = 'jid-single'
    209:           when :list_multi then attributes['type'] = 'list-multi'
    210:           when :list_single then attributes['type'] = 'list-single'
    211:           when :text_multi then attributes['type'] = 'text-multi'
    212:           when :text_private then attributes['type'] = 'text-private'
    213:           when :text_single then attributes['type'] = 'text-single'
    214:           else attributes['type'] = nil
    215:         end
    216:       end

value()

Get the first value

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 257
    257:       def value
    258:         values.first
    259:       end

value=(val)

Remove all and set one value

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 263
    263:       def value=(val)
    264:         self.values = [val]
    265:       end

values()

Get the values (in a Data Form with type=‘submit’)

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 238
    238:       def values
    239:         res = []
    240:         each_element('value') { |e|
    241:           res << e.text
    242:         }
    243:         res
    244:       end

values=(ary)

Set the values

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 248
    248:       def values=(ary)
    249:         delete_elements('value')
    250:         ary.each { |v|
    251:           add(REXML::Element.new('value')).text = v
    252:         }
    253:       end

var()

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 162
    162:       def var
    163:         attributes['var']
    164:       end

var=(s)

[Source]

         # File lib/xmpp4r/dataforms/x/data.rb, line 166
    166:       def var=(s)
    167:         attributes['var'] = s
    168:       end

[Validate]