Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

The initial version of formFor implementation

  • Loading branch information...
commit 95e22319e3d473a5a3fc5522f7d7e473ec866eed 1 parent f28cd30
Boris Staal inossidabile authored
2  Gruntfile.coffee
View
@@ -99,7 +99,6 @@ module.exports = (grunt) ->
[
'joosy/resources/index.coffee',
'joosy/form.coffee',
- 'joosy/helpers/form.coffee',
'spec/joosy/form/**/*_spec.coffee'
]
)
@@ -118,7 +117,6 @@ module.exports = (grunt) ->
[
'joosy/resources/index.coffee',
'joosy/form.coffee',
- 'joosy/helpers/form.coffee',
'spec/joosy/environments/amd_spec.coffee'
]
)
250 source/joosy/helpers/form.coffee
View
@@ -1,250 +0,0 @@
-#
-# Form is an internally-used instance of `formFor` block.
-#
-# @nodoc
-#
-class Form
- constructor: (@context, @resource, @options) ->
-
- __extend: (options) ->
- options.extendIds = @options.extendIds
- options
-
- for type in ['text', 'file', 'hidden', 'password']
- do (type) =>
- @::[type+'Field'] = (property, options={}) ->
- @context[type+'Field'] @resource, property, @__extend(options)
-
- label: (property, options={}, content='') ->
- # (property, content) ->
- if arguments.length == 2
- content = options
- options = {}
-
- @context.label @resource, property, @__extend(options), content
-
- radioButton: (property, tagValue, options={}) ->
- @context.radioButton @resource, property, tagValue, @__extend(options)
-
- textArea: (property, options={}) ->
- @context.textArea @resource, property, @__extend(options)
-
- checkBox: (property, options={}, checkedValue=1, uncheckedValue=0) ->
- @context.checkBox @resource, property, @__extend(options), checkedValue, uncheckedValue
-
- select: (property, selectOptions={}, options={}) ->
- @context.select @resource, property, selectOptions, @__extend(options)
-
-#
-# Form helper
-#
-Joosy.helpers 'Application', ->
-
- #
- # Internally-used helper allowing to split hash into two by a list of keys
- #
- # @param [Hash] options Original hash
- # @param [Array<String>] Keys to separate
- # @return [Array<Hash>]
- #
- separateOptions = (options, keys) ->
- attributes = {}
- parameters = {}
-
- for key, value of options
- if keys.indexOf(key) != -1
- parameters[key] = value
- else
- attributes[key] = value
-
- [parameters, attributes]
-
- #
- # Generates main attributes of a single field for a form
- #
- # @param [String] resource Name of resource
- # @param [Object] resource Instance of something that includes Joosy.Modules.Resources.Module
- # @param [String] property Name of attribute the field is for
- # @param [Boolean] extendIds Marks whether DOM id of a field should contain primary key of resource
- # @param [String] idSuffix Suffix to append to DOM id
- # @param [Hash] DOM attributes Initial set that should be extended
- #
- domify = (resource, property, extendIds, idSuffix, attributes) ->
- if resource.__entityName? && resource.id?
- resourceId = resource.id()
- resource = resource.__entityName
-
- unless attributes
- attributes = {}
- else
- attributes = Joosy.Module.merge {}, attributes
-
- attributes.name = resource
- attributes.name += if property.match(/^\[.*\]$/) then property else "[#{property}]"
-
- # Parameterizing property
- property = property.replace(/[^a-z0-9\-_]+/gi, '_')
- property = property.replace /^_+|_+$|(_)_+/g, '$1'
- property = property.toLowerCase()
-
- attributes.id = resource
- attributes.id += "_#{resourceId}" if resourceId? && extendIds
- attributes.id += "_#{property}"
- attributes.id += "_#{idSuffix}" if idSuffix
-
- attributes
-
- #
- # Generates input field
- #
- input = (type, resource, property, extendIds, idSuffix, attributes={}) =>
- attributes.type = type
- attributes = domify(resource, property, extendIds, idSuffix, attributes)
-
- @tag 'input', attributes
-
- #
- # ======================================================================
- #
-
- #
- # Instantiates a form builder
- #
- # @param [String] resource Name of resource
- # @param [Object] resource Instance of something that includes Joosy.Modules.Resources.Module
- # @param [Function] block Inline template that will be rendered as a form
- # @param [Object] options
- #
- # @option options [Boolean] extendIds Marks if DOM ids of fields should include primary key of resource (default: false)
- #
- # @example
- # != @formFor Resource, {extendIds: true}, (form) =>
- # != form.textField 'property'
- #
- @formFor = (resource, options={}, block) ->
- # (options, block) ->
- if arguments.length == 2
- block = options
- options = {}
-
- uuid = Joosy.uuid()
- attributes = Joosy.Module.merge(options.html || {}, id: uuid)
- form = new Form @, resource, options
-
- @contentTag 'form', block?.call(@, form), attributes
-
- #
- # Generates `label` tag
- #
- # @param [String] resource Name of resource
- # @param [Object] resource Instance of something that includes Joosy.Modules.Resources.Module
- # @param [String] property Attribute of a resource to use
- # @param [Object] options
- # @option options [Boolean] extendIds Marks if DOM ids of fields should include primary key of resource (default: false)
- # @param [String] content Content of the label
- #
- @label = (resource, property, options={}, content='') ->
- # (resource, property, content) ->
- if arguments.length == 3
- content = options
- options = {}
-
- [parameters, attributes] = separateOptions options, ['extendIds']
-
- attributes.for = domify(resource, property, parameters.extendIds, '', attributes).id
-
- @contentTag 'label', content, attributes
-
- #
- # Set of typical generators for basic inputs: textField, fileField, hiddenField, passwordField
- #
- for type in ['text', 'file', 'hidden', 'password']
- do (type) =>
- @[type+'Field'] = (resource, property, options={}) ->
- [parameters, attributes] = separateOptions options, ['extendIds']
-
- input type, resource, property, parameters.extendIds, '', attributes
-
- #
- # Generates a radio button
- #
- # @param [String] resource Name of resource
- # @param [Object] resource Instance of something that includes Joosy.Modules.Resources.Module
- # @param [String] property Attribute of a resource to use
- # @param [Object] options
- # @option options [Boolean] extendIds Marks if DOM ids of fields should include primary key of resource (default: false)
- # @param [String] tagValue Value of the button
- #
- @radioButton = (resource, property, tagValue, options={}) ->
- [parameters, attributes] = separateOptions(options, ['extendIds'])
-
- attributes.value = tagValue
- input 'radio', resource, property, options.extendIds, tagValue, attributes
-
- #
- # Generates a checkbox
- #
- # @param [String] resource Name of resource
- # @param [Object] resource Instance of something that includes Joosy.Modules.Resources.Module
- # @param [String] property Attribute of a resource to use
- # @param [Object] options
- # @option options [Boolean] extendIds Marks if DOM ids of fields should include primary key of resource (default: false)
- # @param [String] checkedValue Value for the checked condition
- # @param [String] uncheckedValue Value for the unchecked condition
- #
- @checkBox = (resource, property, options={}, checkedValue=1, uncheckedValue=0) ->
- [parameters, attributes] = separateOptions(options, ['extendIds'])
-
- spyAttributes = domify resource, property, parameters.extendIds, '', attributes
- spy = @tag 'input', name: spyAttributes.name, value: uncheckedValue, type: 'hidden'
-
- attributes.value = checkedValue
- box = input 'checkbox', resource, property, parameters.extendIds, '', attributes
-
- spy+box
-
- #
- # Generates a select
- #
- # @param [String] resource Name of resource
- # @param [Object] resource Instance of something that includes Joosy.Modules.Resources.Module
- # @param [String] property Attribute of a resource to use
- # @param [Object] options
- # @option options [Boolean] extendIds Marks if DOM ids of fields should include primary key of resource (default: false)
- # @option options [String] value Sets current value of a select
- # @option options [Boolean] includeBlank Marks if select should contain blank starting option
- # @param [Object] selectOptions Options to build select with `{foo: 'bar'}`
- # @param [Array] selectOptions Options to build select with `['foo', 'bar']`
- #
- @select = (resource, property, rawSelectOptions, options) ->
- [parameters, attributes] = separateOptions(options, ['extendIds', 'value', 'includeBlank'])
-
- if rawSelectOptions instanceof Array
- selectOptions = rawSelectOptions
- else
- selectOptions = []
- selectOptions.push [val, key] for key, val of rawSelectOptions
-
- selectOptions.unshift ['', ''] if parameters.includeBlank
- selectOptions = selectOptions.reduce (str, vals) =>
- params = if (vals instanceof Array) then ['option', vals[0], { value: vals[1] }] else ['option', vals, {}]
- if parameters.value == (if (vals instanceof Array) then vals[1] else vals)
- params[2].selected = 'selected'
- str += @contentTag.apply @, params
- , ''
-
- @contentTag 'select', selectOptions, domify(resource, property, parameters.extendIds, '', attributes)
-
- #
- # Generates a text area
- #
- # @param [String] resource Name of resource
- # @param [Object] resource Instance of something that includes Joosy.Modules.Resources.Module
- # @param [String] property Attribute of a resource to use
- # @param [Object] options
- # @option options [Boolean] extendIds Marks if DOM ids of fields should include primary key of resource (default: false)
- # @option options [String] value Value of the text area
- #
- @textArea = (resource, property, options={}) ->
- [parameters, attributes] = separateOptions(options, ['extendIds', 'value'])
- @contentTag 'textarea', parameters.value, domify(resource, property, parameters.extendIds, '', attributes)
248 source/joosy/helpers/form_for.coffee
View
@@ -0,0 +1,248 @@
+Joosy.helpers 'Application', ->
+
+ @formFor = (resource, options={}, block=false) ->
+ if typeof options == "function"
+ block = options
+ options = {}
+
+ attributes = options.html || {}
+ delete options.html
+
+ formBuilder = new Joosy.Helpers.FormBuilder(@, resource, options)
+ attributes.id = formBuilder.__id
+
+ @contentTag 'form', block?.call(@, formBuilder), attributes
+
+#
+# @nodoc
+#
+class Joosy.Helpers.FormBuilder
+ constructor: (@__template, @__resources, @__options) ->
+ @__id = Joosy.uid()
+ @__buckets = {}
+ @__resource = @__resources[@__resources.length-1]
+
+ if @__resource.get && @__resource.set && @__resource.bind
+ @__template.onRendered =>
+ form = document.getElementById(@__id)
+ return unless form?
+
+ for input in form.elements
+ continue unless input.name? && input.name.length > 0 && input.getAttribute('data-form') == @__id
+
+ @__buckets[input.name] ||= []
+ @__buckets[input.name].push input
+
+ input.addEventListener 'change', (
+ (ev) => @__inputToResource input
+ ), false
+
+ @__binding = @__resource.bind 'changed', =>
+ @__formFromResource()
+
+ @__template.onRemoved =>
+ if @__binding?
+ @__resource.unbind @__binding
+ delete @__binding
+
+ #
+ # Global helpers
+ #
+ __withInheritedOptions: (inputOptions) ->
+ options = Joosy.Module.merge {}, @__options
+ Joosy.Module.merge options, inputOptions
+ options
+
+ __stabilize: (block) ->
+ return if @__unstable
+
+ @__unstable = true
+ try
+ block()
+ finally
+ delete @__unstable
+
+ #
+ # Synchronization helpers
+ #
+ __isCheckOrRadioBox: (input) ->
+ input instanceof HTMLInputElement && (input.type == 'checkbox' || input.type == 'radio')
+
+ __activateGroupInput: (input) ->
+ if @__isCheckOrRadioBox(input)
+ input.checked = true
+
+ __deactivateGroupInput: (input) ->
+ if @__isCheckOrRadioBox(input)
+ input.checked = false
+
+ __isGroupInputActive: (input) ->
+ if @__isCheckOrRadioBox(input)
+ input.checked
+ else
+ true
+
+ __inputToResource: (input) ->
+ @__stabilize =>
+ if @__isCheckOrRadioBox(input)
+ for neighbor in @__buckets[input.name]
+ if @__isGroupInputActive(input)
+ value = neighbor.value
+ else
+ value = input.value
+
+ # Type casting
+ value = switch input.type
+ when 'checkbox'
+ value != '0'
+ else
+ value
+
+ @__resource.set input.getAttribute('data-to'), value
+
+ __formFromResource: ->
+ @__stabilize =>
+ for name, inputs of @__buckets
+ value = @__resource.get inputs[0].getAttribute('data-to')
+
+ # Type casting
+ value = switch inputs[0].type
+ when 'checkbox'
+ if value
+ '1'
+ else
+ '0'
+ else
+ value
+
+ for input in inputs
+ if @__isCheckOrRadioBox(input)
+ if input.value == value
+ @__activateGroupInput input
+ else
+ @__deactivateGroupInput input
+ else
+ input.value = value
+
+ #
+ # Builder helpers
+ #
+ __generateId: (property, suffix) ->
+ resourceName = @__resource.__entityName || @_resource.toString()
+ resourceId = @__resource.id?()
+
+ parameterizedProperty =
+ property.replace(/[^a-z0-9\-_]+/gi, '_')
+ .replace(/^_+|_+$|(_)_+/g, '$1')
+ .toLowerCase()
+
+ id = resourceName
+ id = "#{@__options.namespace}_#{id}" if @__options.namespace?.length > 0
+ id += "_#{resourceId}" if resourceId?
+ id += "_#{parameterizedProperty}"
+ id += "_#{suffix}" if suffix?.length > 0
+
+ id
+
+ __generateInput = (type, property, attributes={}, value=undefined, suffix = '') ->
+ attributes.type = type
+ attributes.id = @__generateId property, suffix
+ attributes.name = property
+ attributes.value = value if value?
+ attributes['data-to'] = property
+
+ @tag 'input', attributes
+
+ #
+ # Methods
+ #
+ fieldsFor: (resource, options={}, block) ->
+ if typeof options == 'function'
+ block = options
+ options = {}
+
+ fieldBuilder = new FormBuilder @__template, @__resources.concat(resource), @__withInheritedOptions(options)
+
+ @__template.contentTag 'fieldset', {id: fieldBuilder.__id}, =>
+ block.call @__template, fieldBuilder
+
+ label: (property, attributes={}, content='') ->
+ if typeof attributes == 'string' || typeof attributes == 'function'
+ content = attributes
+ attributes = {}
+
+ attributes.for = @__generateId property
+
+ @contentTag 'label', attributes, content
+
+ for type in [ 'text', 'file', 'hidden', 'password' ]
+ do (type) =>
+ @::[inputType + 'Field'] = (property, attributes={}) ->
+ attributes.value ||= @__resource.get(property)
+
+ @__generateInput type, property, attributes
+
+ radioButton: (property, tagValue, attributes={}) ->
+ if @__resource.get(property) == tagValue
+ attributes.checked = 'checked'
+
+ @__generateInput 'radio', property, attributes, tagValue
+
+ textArea: (property, attributes={}) ->
+ value = attributes.value
+ value ||= @__resource.get(property)
+
+ delete attributes.value
+
+ attributes.id = @__generateId property
+ attributes.name = property
+ attributes['data-to'] = property
+
+ @contentTag 'textarea', attributes, value
+
+ checkBox: (property, attributes={}, checkedValue="1", uncheckedValue="0") ->
+ attributes.checked = 'checked' if @__resource.get(property)
+
+ hidden = @__generateInput 'hidden', property, attributes, uncheckedValue, 'default'
+ hidden + @__generateInput('checkbox', property, attributes, checkedValue)
+
+ select: (property, selectOptions={}, attributes={}) ->
+ value = attributes.value
+ blank = attributes.includeBlank
+ value ||= @__resource.get(property)
+
+ delete attributes.value
+ delete attributes.includeBlank
+
+ optionArray = []
+ if selectOptions instanceof Array
+ optionArray = selectOptions.slice(0)
+ else
+ optionArray = []
+ for key, value of selectOptions
+ optionArray.push [ value, key ]
+
+ optionArray.push [ '', '' ] if blank
+
+ optionsHtml = ''
+
+ for option in optionArray
+ optionAttributes = {}
+
+ if option instanceof Array
+ content = option[0]
+ optionAttributes.value = option[1]
+ else
+ content = option
+ optionAttributes.value = option
+
+ if value? && optionAttributes.value == value
+ optionAttributes.selected = 'selected'
+
+ optionsHtml += @contentTag 'option', content, optionAttributes
+
+ attributes.id = @__generateId property
+ attributes.name = property
+ attributes['data-to'] = property
+
+ @contentTag 'select', optionsHtml, attributes
10 source/joosy/resources/array.coffee
View
@@ -54,14 +54,20 @@ class Joosy.Resources.Array extends Array
#
# Sets element by its index
#
+ # @param [Integer] index Index to set to
+ # @param [Mixed] value The value to set
+ # @param [Object] options
+ #
+ # @option options [Boolean] silent Suppresses modification trigger
+ #
# @example
# data = Joosy.Resources.Array.build 1, 2, 3
# data.set(0, 2) # 2
# data # [2, 2, 3]
#
- set: (index, value) ->
+ set: (index, value, options={}) ->
@[index] = value
- @trigger 'changed'
+ @trigger 'changed' unless options.silent
value
#
8 source/joosy/resources/hash.coffee
View
@@ -74,13 +74,17 @@ class Joosy.Resources.Hash extends Joosy.Module
#
# @param [String] path The path to the field that should be resolved
# @param [Mixed] value The value to set
+ # @param [Object] options
+ #
+ # @option options [Boolean] silent Suppresses modification trigger
+ #
# @note Can resolve nested fields
#
# @example
# data.set('field', {subfield: 'value'})
# data.set('field.subfield', 'value2')
#
- set: (path, value) ->
+ set: (path, value, options={}) ->
[instance, property] = @__callTarget path
if instance.set?
@@ -88,7 +92,7 @@ class Joosy.Resources.Hash extends Joosy.Module
else
instance[property] = value
- @trigger 'changed'
+ @trigger 'changed' unless options.silent
value
#
3  source/joosy/resources/index.coffee
View
@@ -1,2 +1,3 @@
#= require_tree ./
-#= require_tree ../modules/resources
+#= require_tree ../modules/resources
+#= require ../helpers/form_for
4 source/joosy/resources/rest_collection.coffee
View
@@ -4,6 +4,10 @@
# REST collection data
#
class Joosy.Resources.RESTCollection extends Joosy.Resources.Array
+ #
+ # @param [Joosy.Resources.REST] __resource Resource this collection contains
+ # @param [String] __where Location the collection has been fetched from
+ #
constructor: (@__resource, @__where) ->
@beforeLoad (data) ->
13 source/joosy/resources/scalar.coffee
View
@@ -38,7 +38,7 @@ class Joosy.Resources.Scalar extends Joosy.Module
@load value
#
- # Replaces the value with given
+ # Replaces the value with given (applies beforeLoad)
#
# @example
# data = Joosy.Resources.Scalar.build 1
@@ -57,12 +57,17 @@ class Joosy.Resources.Scalar extends Joosy.Module
@value
#
- # Replaces the value with given
+ # Replaces the value with given (doesn't apply beforeLoad)
+ #
+ # @param [Mixed] value The value to set
+ # @param [Object] options
+ #
+ # @option options [Boolean] silent Suppresses modification trigger
#
# @see Joosy.Resources.Scalar.load
#
- set: (@value) ->
- @trigger 'changed'
+ set: (@value, options={}) ->
+ @trigger 'changed' unless options.silent
#
# JS helper converting object to its internal value during basic operations
108 spec/joosy/form/helpers/forms_spec.coffee
View
@@ -1,108 +0,0 @@
-describe "Joosy.Helpers.Form", ->
- class Test extends Joosy.Resources.REST
- @entity 'test'
-
- h = Joosy.Helpers.Application
- resource = Test.build id: 1
-
- describe "simple", ->
- for type in ['text', 'file', 'hidden', 'password']
- it "renders #{type}Field", ->
- expect(h["#{type}Field"] 'a', 'b', {a: 'b'}).toBeTag 'input', '', id: 'a_b', name: 'a[b]', a: 'b', type: type
-
- it "renders nested methods", ->
- expect(h.textField 'a', '[b]', {a: 'b'}).toBeTag 'input', '', id: 'a_b', name: 'a[b]', a: 'b', type: 'text'
- expect(h.textField 'a', '[b][c]', {a: 'b'}).toBeTag 'input', '', id: 'a_b_c', name: 'a[b][c]', a: 'b', type: 'text'
-
- it "renders label", ->
- expect(h.label 'a', 'b', 'test').toBeTag 'label', 'test', for: 'a_b'
- expect(h.label 'a', 'b', {a: 'b'}, 'test').toBeTag 'label', 'test', for: 'a_b', a: 'b'
-
- it "renders checkBox", ->
- tags = h.checkBox('a', 'b', {a: 'b'}).match(/<[^>]+>/g)
-
- expect(tags[0]).toBeTag 'input', '', value: '0', name: 'a[b]', type: 'hidden'
- expect(tags[1]).toBeTag 'input', '', value: '1', id: 'a_b', name: 'a[b]', type: 'checkbox', a: 'b'
-
- it "renders radioButton", ->
- expect(h.radioButton 'a', 'b', 'test', {a: 'b'}).toBeTag 'input', '', value: 'test', id: 'a_b_test', name: 'a[b]', type: 'radio', a: 'b'
-
- it "renders textArea", ->
- expect(h.textArea 'a', 'b', {a: 'b', value: 'foo'}).toBeTag 'textarea', 'foo', id: 'a_b', name: 'a[b]', a: 'b'
-
- it "renders select with options object", ->
- expect(tag = h.select 'a', 'b', {a: 'b', c: 'd'}, {a: 'b', value: 'c', includeBlank: true}).toBeTag 'select', false, id: 'a_b', name: 'a[b]', a: 'b'
- opts = $ $(tag).html()
- expect(opts.length).toEqual 3
- expect(opts[0]).toBeTag 'option', '', value: ''
- expect(opts[1]).toBeTag 'option', 'b', value: 'a'
- expect(opts[2]).toBeTag 'option', 'd', value: 'c', selected: 'selected'
-
- it "renders select with options array", ->
- expect(tag = h.select 'a', 'b', [['b', 'a'], ['d', 'c']], {a: 'b'}).toBeTag 'select', false, id: 'a_b', name: 'a[b]', a: 'b'
- opts = $ $(tag).html()
- expect(opts.length).toEqual 2
- expect(opts[0]).toBeTag 'option', 'b', value: 'a'
- expect(opts[1]).toBeTag 'option', 'd', value: 'c'
-
- it "renders formFor", ->
- callback = sinon.spy()
- expect(h.formFor resource, callback).toBeTag 'form', '', id: /.*/
- expect(callback.callCount).toEqual 1
- expect(callback.args[0][0].label?).toBeTruthy()
-
- describe "resource", ->
- callback = sinon.spy()
- h.formFor(resource, callback)
- form = callback.args[0][0]
-
- for type in ['text', 'file', 'hidden', 'password']
- it "renders #{type}Field", ->
- expect(form["#{type}Field"] 'b', {a: 'b'}).toBeTag 'input', '', id: 'test_b', name: 'test[b]', a: 'b', type: type
-
- it "renders label", ->
- expect(form.label 'b', 'test').toBeTag 'label', 'test', for: 'test_b'
- expect(form.label 'b', {a: 'b'}, 'test').toBeTag 'label', 'test', for: 'test_b', a: 'b'
-
- it "renders checkBox", ->
- tags = form.checkBox('b', {a: 'b'}).match(/<[^>]+>/g)
-
- expect(tags[0]).toBeTag 'input', '', value: '0', name: 'test[b]', type: 'hidden'
- expect(tags[1]).toBeTag 'input', '', value: '1', id: 'test_b', name: 'test[b]', type: 'checkbox', a: 'b'
-
- it "renders radioButton", ->
- expect(form.radioButton 'b', 'test', {a: 'b'}).toBeTag 'input', '', value: 'test', id: 'test_b_test', name: 'test[b]', type: 'radio', a: 'b'
-
- it "renders textArea", ->
- expect(form.textArea 'b', {a: 'b', value: 'foo'}).toBeTag 'textarea', 'foo', id: 'test_b', name: 'test[b]', a: 'b'
-
- it "renders select", ->
- expect(form.select 'b', {a: 'b', c: 'd'}, {a: 'b'}).toBeTag 'select', false, id: 'test_b', name: 'test[b]', a: 'b'
-
- describe "resource with extendIds", ->
- callback = sinon.spy()
- h.formFor(resource, extendIds: true, callback)
- form = callback.args[0][0]
-
- for type in ['text', 'file', 'hidden', 'password']
- it "renders #{type}Field", ->
- expect(form["#{type}Field"] 'b', {a: 'b'}).toBeTag 'input', '', id: 'test_1_b', name: 'test[b]', a: 'b', type: type
-
- it "renders label", ->
- expect(form.label 'b', 'test').toBeTag 'label', 'test', for: 'test_1_b'
- expect(form.label 'b', {a: 'b'}, 'test').toBeTag 'label', 'test', for: 'test_1_b', a: 'b'
-
- it "renders checkBox", ->
- tags = form.checkBox('b', {a: 'b'}).match(/<[^>]+>/g)
-
- expect(tags[0]).toBeTag 'input', '', value: '0', name: 'test[b]', type: 'hidden'
- expect(tags[1]).toBeTag 'input', '', value: '1', id: 'test_1_b', name: 'test[b]', type: 'checkbox', a: 'b'
-
- it "renders radioButton", ->
- expect(form.radioButton 'b', 'test', {a: 'b'}).toBeTag 'input', '', value: 'test', id: 'test_1_b_test', name: 'test[b]', type: 'radio', a: 'b'
-
- it "renders textArea", ->
- expect(form.textArea 'b', {a: 'b', value: 'foo'}).toBeTag 'textarea', 'foo', id: 'test_1_b', name: 'test[b]', a: 'b'
-
- it "renders select", ->
- expect(form.select 'b', {a: 'b', c: 'd'}, {a: 'b'}).toBeTag 'select', false, id: 'test_1_b', name: 'test[b]', a: 'b'
1  spec/joosy/resources/helpers/forms_for_spec.coffee
View
@@ -0,0 +1 @@
+describe "Joosy.Helpers.FormFor", ->
Please sign in to comment.
Something went wrong with that request. Please try again.