Skip to content

Commit

Permalink
Fixed bug when using [input] checkbox with param.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Apr 16, 2012
1 parent 90bb50f commit 5b9c452
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ def r_input(skip_col = false)
@markup.set_param(:type, @params[:type] || 'text')

checked = html_attributes.delete(:checked)
puts checked.inspect
@markup.set_dyn_params(html_attributes)
@markup.append_attribute checked if checked
@markup.done = false
Expand Down Expand Up @@ -623,7 +624,13 @@ def get_input_params(params = @params)
res = Zafu::OrderedHash.new
if name = (params[:param] || params[:name] || params[:date])
res[:name] = name
unless params[:param]
if params[:param]
if name =~ /^[a-z_]+$/
sub_attr_ruby = "params[:#{name}]"
else
sub_attr_ruby = "param_value(#{name.inspect})"
end
else
# build name
if res[:name] =~ /\A([\w_]+)\[(.*?)\]/
# Sub attributes are used with tags or might be used for other features. It
Expand All @@ -639,7 +646,7 @@ def get_input_params(params = @params)
res[:name] = "#{node.form_name}[#{attribute}]"
end
end

if sub_attr
type = node.klass.safe_method_type([attribute])
if sub_attr_ruby = RubyLess.translate(self, %Q{this.#{attribute}[#{sub_attr.inspect}]})
Expand All @@ -656,11 +663,7 @@ def get_input_params(params = @params)
res[:value] = "<%= fquote #{value} %>"
end
elsif params[:param]
if name =~ /^[a-z_]+$/
res[:value] = "<%= fquote params[:#{name}] %>"
else
res[:value] = "<%= fquote param_value(#{name.inspect}) %>"
end
res[:value] = "<%= fquote #{sub_attr_ruby} %>"
elsif attribute && type = node.klass.safe_method_type([attribute])
res[:value] = "<%= fquote #{node}.#{type[:method]} %>"
end
Expand Down Expand Up @@ -695,7 +698,7 @@ def get_input_params(params = @params)
else
res[:id] = params[:id] if params[:id]
end

if params[:type] == 'checkbox' && sub_attr_ruby
if value = params[:value]
res[:checked] = "<%= #{sub_attr_ruby} == #{value.inspect} ? \" checked='checked'\" : '' %>"
Expand Down
8 changes: 8 additions & 0 deletions test/integration/zafu_compiler/forms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ input_param_value:
tem: "<input type='text' name='foo[bar.baz]' value='<%= fquote param_value(\"foo[bar.baz]\") %>'/>"
res: "<input type='text' name='foo[bar.baz]' value='xyz'/>"

input_checkbox_param_value:
context:
foo:
"bar.baz": 'null'
src: "<r:input type='checkbox' value='null' param='foo[bar.baz]'/>"
tem: "<input type='hidden' name='foo[bar.baz]' value=''/><input type='checkbox' name='foo[bar.baz]' value='null'<%= param_value(\"foo[bar.baz]\") == \"null\" ? \" checked='checked'\" : '' %>/>"
res: "<input type='hidden' name='foo[bar.baz]' value=''/><input type='checkbox' name='foo[bar.baz]' value='null' checked='checked'/>"

select_param_value:
context:
foo:
Expand Down

0 comments on commit 5b9c452

Please sign in to comment.