Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form label with block shouldn't insert name automatically #27

Open
robacarp opened this issue Jun 12, 2018 · 1 comment
Open

form label with block shouldn't insert name automatically #27

robacarp opened this issue Jun 12, 2018 · 1 comment

Comments

@robacarp
Copy link
Member

With this code:

== form action: "/", method: :post do
  == csrf_tag
  == label name: "alpha" do
    | beta
    == check_box id="beta"

I get the following html output:

<form action="/" method="post">
  <input type="hidden" name="_csrf" value="..." />
  <label for="alpha" id="alpha_label">
    beta
    <input type="checkbox" name="beta" id="beta" value="1"/>
    <input type="hidden" name="beta" id="beta_default" value="0"/>
+    Alpha
  </label>
</form>

When giving a block to a label, I expect the block to be the contents of the label and nothing more.

currently jasper automatically appends the name

@14tinchov
Copy link
Contributor

14tinchov commented Aug 14, 2018

Hi guys ! I have two ideas for this issue

Option 1

In Rails when you pass a block to a label, the name is not appended, maybe we could remove this

  def label(name : String | Symbol)
    content = "#{yield}"
    label(name, content: content, for: name, id: "#{Kit.css_safe(name)}_label")
  end

So...now we need a method to display our block, maybe we could do it somethings like this

  def wrapper_field(*args)
    return "" unless args.first?
    args.join("")
  end

in our views:

      label(:name) do
        wrapper_field(
          check_box(:allowed),
          "name"
        )

Benefit: in this way you can concatenate many elements in a single method

I created a PR for it

Option 2

We could use a boolean to show the name label but this will only remove the "appends"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants