Also, if you pass a block to the govuk_image_field it will be displayed twice(second one as a string content)
This is because the super method correctly appends the passed block, but concat will treat it as a string.
super(attribute_name, hint:, **kwargs) do
if block
concat(yield)
else
concat(t("helpers.hint.default.image", max_size: @template.number_to_human_size(max_size)))
end
end
Full method for reference.
def govuk_image_field(attribute_name, hint: {}, **kwargs, &block)
max_size = hint[:max_size] || Koi.config.image_size_limit
super(attribute_name, hint:, **kwargs) do
if block
concat(yield)
else
concat(t("helpers.hint.default.image", max_size: @template.number_to_human_size(max_size)))
end
end
end
Example
<%= form.govuk_image_field :image do %>
<div class="govuk-hint">
If you are creating a list of image + text items, ensure all images are sized the same.<br>
Max 500px wide.
</div>
<% end %>
If you pass a proc to the
hint
option, it will error withwrong number of arguments (given 1, expected 0)
This is because in Koi,
Koi::FormBuilder
->govuk_image_field
method we are trying to get the max size supported.Also, if you pass a block to the
govuk_image_field
it will be displayed twice(second one as a string content) This is because thesuper
method correctly appends the passed block, but concat will treat it as a string.Full method for reference.
Example
Rendered view