         callback: (data) ->
           if data
             $el = @$element
+            tsFieldTypes = $el.data('tsFieldTypes')
             model = window.TS.getModel $el.data('ts-url')
           
             vex.dialog.confirm


buildFields = (element) ->
  tsFields = element.data('tsFields')
  inputs = ''
  model = window.TS.getModel element.data('ts-url')
  modelValues = element.data('ts-data')['ts_values']

  for field in tsFields
    label = "<label for='#{field.name}'>#{field.label}</label>"
    input = switch field.type
      when "text" then "<input type='text' name='#{field.name}' id='#{field.name}' value='#{modelValues[field.name]}' />"

              callback: (value) ->
                if value
                  for k,v of data
                    type = tsFieldTypes[k]
                    model.set(k, { field: k, value: v, type: if type == 'multiple_select' then 'multiple_select' else 'text' })
                  model.save ->
                    window.location.reload()

