app/assets/javascripts/formagic/inputs/datetime.coffee in formagic-0.1.0 vs app/assets/javascripts/formagic/inputs/datetime.coffee in formagic-0.2.5

- old
+ new

@@ -19,10 +19,15 @@ # PRIVATE =============================================== _update_value: -> mt = moment(@$inputTime.val(), 'LT') + + if @$inputDate.val() == '' && ! mt.isValid() + @$input.val('') + return + if ! mt.isValid() mt = moment('1:00 pm', 'LT') time_string = mt.utcOffset(@tzOffset).format().split('T')[1] date_string = @$inputDate.val() @@ -42,19 +47,21 @@ @$inputTime.val ( if m.isValid() then m.format('h:mm a') else '' ) _update_date_label: -> m = moment(@$inputDate.val()).utcOffset(@tzOffset) - @$dateLabel.html ( if m.isValid() then m.format('dddd, MMM D, YYYY') else 'Pick a date' ) + label = if m.isValid() then m.format('dddd, MMM D, YYYY') else "<span class='placeholder'>Pick a date</span>" + @$dateLabel.html label _normalized_value: -> # -- use local timezone to represent time @tzOffset = @config.timezoneOffset @tzOffset ?= (new Date()).getTimezoneOffset() * -1 - @value = moment(@value).utcOffset(@tzOffset).format() + m = moment(@value).utcOffset(@tzOffset) + @value = if m.isValid() then m.format() else '' _add_input: -> @_normalized_value() @@ -85,9 +92,30 @@ @$inputTime =$ "<input type='text' class='input-datetime-time' placeholder='1:00 pm' />" @$el.append @$inputTime @$inputTime.on 'change, keyup', (e) => @_update_value() ; @$input.trigger('change') @_update_time_input() + + @_add_actions() + + + _add_actions: -> + @$actions =$ "<span class='input-actions'></span>" + @$label.append @$actions + + @_add_remove_button() + + + _add_remove_button: -> + @$removeBtn =$ "<a href='#' class='remove'>Remove</a>" + @$actions.append @$removeBtn + + @$removeBtn.on 'click', (e) => + e.preventDefault() + @$inputTime.val('') + @$inputDate.val('') + @_update_date_label() + @_update_value() # PUBLIC ================================================ initialize: ->