app/assets/javascripts/formagic/inputs/checkbox.coffee in formagic-0.3.4 vs app/assets/javascripts/formagic/inputs/checkbox.coffee in formagic-0.3.7

- old
+ new

@@ -1,14 +1,9 @@ # ----------------------------------------------------------------------------- # Author: Alexander Kravets <alex@slatestudio.com>, # Slate Studio (http://www.slatestudio.com) -# -# Coding Guide: -# https://github.com/thoughtbot/guides/tree/master/style/coffeescript # ----------------------------------------------------------------------------- - -# ----------------------------------------------------------------------------- # INPUT CHECKBOX # ----------------------------------------------------------------------------- class @InputCheckbox extends InputString constructor: (@name, @value, @config, @object) -> @_create_el() @@ -16,54 +11,47 @@ @_add_label() @_add_disabled() return this + # PRIVATE =================================================================== - # PRIVATE =============================================== - _create_el: -> @$el =$ "<label for='#{ @name }' class='form-input input-#{ @config.type } input-#{ @config.klassName }'>" - _safe_value: -> if not @value or @value == 'false' or @value == 0 or @value == '0' return false else return true - _add_input: -> # for boolean checkbox to be serialized correctly we need a hidden false # value which is used by default and overriden by checked value @$false_hidden_input =$ "<input type='hidden' name='#{ @name }' value='false' />" @$el.append @$false_hidden_input @$input =$ "<input type='checkbox' id='#{ @name }' name='#{ @name }' value='true' #{ if @_safe_value() then 'checked' else '' } />" @$el.append @$input + # PUBLIC ==================================================================== - # PUBLIC ================================================ - updateValue: (@value) -> @$input.prop('checked', @_safe_value()) - hash: (hash={}) -> hash[@config.klassName] = @$input.prop('checked') return hash - chr.formInputs['checkbox'] = InputCheckbox - # ----------------------------------------------------------------------------- # INPUT CHECKBOX SWITCH # ----------------------------------------------------------------------------- class @InputCheckboxSwitch extends InputCheckbox - # PRIVATE =============================================== + # PRIVATE =================================================================== _add_input: -> @$switch =$ "<div class='switch'>" @$el.append @$switch @@ -74,11 +62,6 @@ @$switch.append @$input @$checkbox =$ "<div class='checkbox'>" @$switch.append @$checkbox - chr.formInputs['switch'] = InputCheckboxSwitch - - - -