Sha256: 2dbf1712a014fb3d62993c9ae72e396deb2dfafc04c0325848e84d098f20ab45

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

# Fake file input (bootstrap style)
window.setupUploadInputs = (scope = document) ->
  $(scope).find(".form-control.upload").map ->
    container = $(this)
    form      = container.parents("form")
    input     = container.find("[type=file]")
    label     = container.find("label")
    submit    = form.find("[type=submit]")
    progress  = form.find(".progress")

    progress.hide() if not xhr2_available()

    label.map ->
      this.dataset.defaultValue = $(this).html()

    input.change ->
      if this.value == ""
        submit.prop(disabled: true) if input.hasClass("required")
        label_value = label.data("defaultValue")
      else
        submit.prop(disabled: false)
        label_value = this.value.split("/").pop().split("\\").pop()

      label.html(label_value)
    input.change()

$(document).on "ready turbolinks:load page:load", ->
  $("button.reset").click ->
    form = $(this).parents("form")

    form.find("select option:first-child").map ->
      this.selected = true

    form.find("input").map ->
      return if this.type.match(/submit|hidden|button/)
      this.value = $(this).data("default-value") || ""

    form.find("textarea").map ->
      this.value = $(this).data("default-value") || ""

    form.find("select").map ->
      this.selectize.clear() if this.selectize
      $(this).val("").trigger("change")

  # Referer with anchor
  $("form").submit ->
    return if this.method.toUpperCase() == "GET"
    return if $(this).find("[name=form_url]").length > 0

    input       = document.createElement("input")
    input.type  = "hidden"
    input.name  = "form_url"
    input.value = location.href
    $(this).append(input)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dorsale-3.1.5 app/assets/javascripts/dorsale/common/forms.coffee
dorsale-3.1.4 app/assets/javascripts/dorsale/common/forms.coffee