#= require ultimate/underscore/underscore
#= require ultimate/underscore/underscore.string
#= require ultimate/underscore/underscore.outcasts
#= require ultimate/helpers/form_tag
module "Ultimate.Helpers.FormTag"
_.extend @, Ultimate.Helpers.FormTag
hidden_fields = (options = {}) ->
method = options['method']
txt = '
'
txt += ''
if method and not (method in ['get', 'post'])
txt += ''
txt + '
'
form_text = (action = 'http://www.example.com', options = {}) ->
[remote, enctype, html_class, id, method] = _.map(_.string.words('remote enctype html_class id method'), (key) -> options[key])
method = 'post' if method isnt 'get'
txt = ""
out
test "form_tag", ->
equal form_tag(), whole_form()
equal form_tag({}, multipart: true), whole_form(null, enctype: true)
equal form_tag({}, method: 'patch'), whole_form(null, method: 'patch')
equal form_tag({}, method: 'put'), whole_form(null, method: 'put')
equal form_tag({}, method: 'delete'), whole_form(null, method: 'delete')
equal form_tag({}, remote: true), whole_form(null, remote: true)
equal form_tag(-> 'Hello world!'), whole_form(null, -> 'Hello world!')
equal form_tag(null, method: 'put', -> 'Hello world!'), whole_form(null, method: 'put', -> 'Hello world!')
test "select_tag", ->
equal select_tag("people", ""),
''
equal select_tag("colors", "", multiple: true),
''
equal select_tag("places", "", disabled: true),
''
equal select_tag("places", "", include_blank: true),
''
equal select_tag("places", "", prompt: "string"),
''
equal select_tag("places", "", prompt: ""),
''
equal select_tag("places", "", prompt: "string", include_blank: true),
''
equal select_tag("places", null, include_blank: true),
''
equal select_tag("places", null, prompt: "string"),
''
test "text_field_tag", ->
equal text_field_tag("title"),
''
equal text_field_tag("title", "Hello!", class: "admin"),
''
equal text_field_tag("title", "Hello!", size: 75),
''
equal text_field_tag("title", "Hello!", disabled: true),
''
equal text_field_tag("title", "Hello!", size: 70, maxlength: 80),
''
test "label_tag", ->
equal label_tag("title"), ''
equal label_tag("title", "My Title"), ''
equal label_tag("title", "My Title", class: "small-label"), ''
equal label_tag( -> "Blocked" ), ''
equal label_tag("clock", -> "Grandfather"), ''
equal label_tag("clock", id: "label_clock", -> "Grandfather"), ''
test "hidden_field_tag", ->
equal hidden_field_tag('id', 3), ''
test "file_field_tag", ->
equal file_field_tag('picsplz'), ''
equal file_field_tag('picsplz', class: 'pix'), ''
test "password_field_tag", ->
equal password_field_tag(), ''
test "text_area_tag", ->
equal text_area_tag("body", "hello world", size: "20x40"),
''
equal text_area_tag("body", "hello world", size: 20),
''
equal text_area_tag("body", "hello world", size: "20x40"),
''
equal text_area_tag("body", "hello world", size: "20x40", escape: false),
''
equal text_area_tag("body", null, escape: false),
''
test "check_box_tag", ->
equal check_box_tag('admin'), ''
test "radio_button_tag", ->
equal radio_button_tag("people", "david"),
''
equal radio_button_tag("num_people", 5),
''
equal radio_button_tag("gender", "m") + radio_button_tag("gender", "f"),
''
equal radio_button_tag("opinion", "-1") + radio_button_tag("opinion", "1"),
''
equal radio_button_tag("person[gender]", "m"),
''
equal radio_button_tag('ctrlname', 'apache2.2'),
''
test "submit_tag", ->
equal submit_tag("Save", onclick: "alert('hello!')", data: { disable_with: "Saving..." }),
''
equal submit_tag("Save", data: { disable_with: "Saving..." }),
''
equal submit_tag("Save", data: { confirm: "Are you sure?" }),
''
test "button_tag", ->
equal button_tag(),
''
equal button_tag("Save", type: "submit"),
''
equal button_tag("Button", type: "button"),
''
equal button_tag("Reset", type: "reset"),
''
equal button_tag("Reset", type: "reset", disabled: true),
''
equal button_tag("Reset", type: "reset", disabled: true),
''
equal button_tag( -> 'Content' ),
''
equal button_tag(name: 'temptation', type: 'button', -> content_tag('strong', 'Do not press me')),
''
equal button_tag("Save", type: "submit", data: { confirm: "Are you sure?" }),
''
test "image_submit_tag", ->
equal image_submit_tag("save.gif", data: { confirm: "Are you sure?" }),
''
test "field_set_tag", ->
equal field_set_tag('Your details', -> 'Hello world!'),
''
equal field_set_tag(-> 'Hello world!'),
''
equal field_set_tag('', -> 'Hello world!'),
''
equal field_set_tag('', class: 'format', -> 'Hello world!'),
''
equal field_set_tag(),
''
equal field_set_tag('You legend!'),
''
test "different fields tags helpers", ->
equal color_field_tag("car"),
''
equal search_field_tag("query"),
''
equal telephone_field_tag("cell"),
''
equal telephone_field_tag("cell"),
phone_field_tag("cell")
equal date_field_tag("cell"),
''
equal time_field_tag("cell"),
''
equal datetime_field_tag("appointment"),
''
equal datetime_local_field_tag("appointment"),
''
equal month_field_tag("birthday"),
''
equal week_field_tag("birthday"),
''
equal url_field_tag("homepage"),
''
equal email_field_tag("address"),
''
equal number_field_tag("quantity", null, in: {min: "1", max: "9"}),
''
equal range_field_tag("volume", null, in: {min: 0, max: 11}, step: 0.1),
''
test "boolean options", ->
equal check_box_tag("admin", 1, true, disabled: true, readonly: "yes"),
''
equal check_box_tag("admin", 1, true, disabled: false, readonly: null),
''
equal tag('input', type: "checkbox", checked: false),
''
equal select_tag("people", "", multiple: true),
''
equal select_tag("people[]", "", multiple: true),
''
equal select_tag("people", "", multiple: null),
''
test "options side effects", ->
options = { option: "random_option" }
text_area_tag "body", "hello world", options
deepEqual options, { option: "random_option" }
submit_tag "submit value", options
deepEqual options, { option: "random_option" }
button_tag "button value", options
deepEqual options, { option: "random_option" }
image_submit_tag "submit source", options
deepEqual options, { option: "random_option" }
label_tag "submit source", "title", options
deepEqual options, { option: "random_option" }