::xowiki::formfield::CompoundField ::xowiki::formfield::CompoundField get_named_sub_component_value json_value ::xowiki::formfield::FormField ::xowiki::formfield::FormField → fc_decode → fc_encode json_value ::xowiki::formfield::CompoundField->::xowiki::formfield::FormField ::xo::tdom::Object ::xo::tdom::Object ::xowiki::formfield::FormField->::xo::tdom::Object ::xowiki::formfield::repeatContainer ::xowiki::formfield::repeatContainer json_value ::xowiki::formfield::repeatContainer->::xowiki::formfield::CompoundField

Class ::xowiki::formfield::repeatContainer

::xowiki::formfield::repeatContainer[i] create ... \
           [ -max (default "5") ] \
           [ -min (default "1") ] \
           [ -repeat_add_label (default "#xowiki.form-repeatable-add#") ] \
           [ -repeat_remove_label (default "#xowiki.delete#") ]

Defined in

Class Relations

  • class: ::xotcl::Class[i]
  • superclass: ::xowiki::formfield::CompoundField[i]
::xotcl::Class create ::xowiki::formfield::repeatContainer \
     -superclass ::xowiki::formfield::CompoundField

Methods (to be applied on instances)

  • json_value (scripted, public)

     <instance of xowiki::formfield::repeatContainer[i]> json_value \
        value

    Recursively export repeated occurrences as a JSON array in numeric occurrence order. Omit the occurrence-zero template and create field metadata for stored occurrences on demand. Invalid legacy values remain strings.

    Parameters:
    value (required)
    Stored dictionary of occurrence names and values.
    Returns:
    Two-element ns_json type/payload pair; array payloads contain triples.

    Testcases:
    No testcase defined.
    if {[catch {dict size $value}]} {
      return [list string $value]
    }
    set occurrences {}
    dict for {name v} $value {
      set prefix ${:name}.
      if {[string first $prefix $name] != 0} {
        return [list string $value]
      }
      set index [string range $name [string length $prefix] end]
      if {![regexp {^(0|[1-9][0-9]*)$} $index]} {
        return [list string $value]
      }
      # Occurrence zero is the client-side template, not content.
      if {$index > 0} {
        lappend occurrences [list $index $name $v]
      }
    }
    set entries {}
    set i 0
    foreach occurrence [lsort -integer -index 0 $occurrences] {
      lassign $occurrence index name v
      set c ""
      foreach component ${:components} {
        if {[$component name] eq $name} {
          set c $component
          break
        }
      }
      if {$c eq ""} {
        set c [:require_component $index]
      }
      lassign [$c json_value $v] type payload
      lappend entries $i $type $payload
      incr i
    }
    return [list array $entries]