function registerHelpers()

in source/static-assets/js/main.js [454:497]


function registerHelpers () {

  /**
   *Builds an input field based on the passed in metadata
   */
  Handlebars.registerHelper('buildInput', function (type, options) {
    var html = ''
    var required = ''

    if (this.required && typeof (this.required) === 'string') {
      required = 'data-validetta="' + this.required + '"'
    } else if (this.required) {
      required = 'data-validetta="required"'
    }

    switch (this.inputType) {
      case 'select':
        html = '<select class="user-attribute-input" data-attribute="' + this.id + '" id="select_' + this.id + '">'
        this.options.forEach((option, index) => {
          html += '<option value="' + option.value + '">' + option.label + '</option>'
        })
        html += '</select>'
        return new Handlebars.SafeString(html)
      case 'checkbox':
        html = '<span class="checkbox-container">'
        this.options.forEach((option, index) => {
          html += '<input type="checkbox" class="user-attribute-checkbox" data-attribute="' + this.id + '" id="checkbox_' + this.id + '_' + index + '" name="' + this.id + '" value="' + option.value + '" ' + required + '> <label class="checkbox-label" for="checkbox_' + this.id + '_' + index + '">' + option.label + '</label>'
        })
        html += '</span>'
        return new Handlebars.SafeString(html)
      case 'radio':
        html = '<span class="radio-container">'
        this.options.forEach((option, index) => {
          html += '<input type="radio" class="user-attribute-radio" data-attribute="' + this.id + '" id="radio_' + this.id + '_' + index + '" name="' + this.id + '" value="' + option.value + '" ' + required + '> <label class="radio-label" for="radio_' + this.id + '_' + index + '">' + option.label + '</label>'
        })
        html += '</span>'
        return new Handlebars.SafeString(html)
      default:
        inputMask = this.inputMask ? 'data-inputmask="' + this.inputMask + '"' : ''
        html = '<input class="user-' + type + '-input" type="text" data-attribute="' + this.id + '" placeholder="' + this.inputPlaceholder + '" id="' + type + '_' + this.id + '_' + options.data.index + '" ' + required + ' ' + inputMask + '/>'
    }
    return new Handlebars.SafeString(html)
  })
}