question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `data-is-checked` to checkbox and radio wrappers.

See original GitHub issue

Describe the feature

Currently, I can’t add regular/static classes + conditional classes.

Simplified example:

    <FormKit  :wrapper-class="myVar && 'test-class'"  wrapper-class="flex items-centercursor-pointer" type="radio"
        :options="options">
    </FormKit>

I know I can probably do something like :class="true && 'flex items-centercursor-pointer'; myVar && 'test-class'" But this is kinda ugly.

I’m building a custom radio input, for which I want to add a border to the active/selected option

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
justin-schroedercommented, Nov 22, 2022

There probably should be a simpler way. We’ll change this issue to reflect that instead. As for what is happening here — FormKit inputs are written (under “the hood”) using FormKit’s Schema — which means you can extend the schema object on a per-section basis. This is a really neat feature that gives you lots of power over the internals of each component that you normally would not have.

The sections-schema prop lets you target a given section with a chunk of schema that will be applied “on top” of the pre-existing one. So in the given example data-is-checked is an attribute that is being added to the option section. It’s value is determined by the schema expression $fns.isChecked($option.value) which basically just checks if that checkbox is checked or not.

0reactions
silveltmancommented, Nov 18, 2022

Thanks! Both solutions work.

However, I find this part quiet robust for simply adding a checked state:

:sections-schema="{
      option: {
        attrs: {
          'data-is-checked': '$fns.isChecked($option.value)'
        }
      }
    }"

Isn’t there a simpler way? And if not, can you please elaborate on what’s happening here? I can’t make it up from the docs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Styling Radio Buttons with CSS (59 Custom Examples)
Radio buttons are website elements that allow a user to select one out of a series of options. They are very similar to...
Read more >
Add a check box or option button (Form controls)
You can insert form controls such as check boxes or option buttons to make data entry easier. Check boxes work well for forms...
Read more >
how to keep radio-button or checkbox and its label together ...
You can wrap the input and label in a <span> or wrap the input inside the label. Either way, the outer container (the...
Read more >
Checkboxes, radio buttons, and menus - Contact Form 7
By default, a checkbox or a radio button are put first, and a label last. By adding label_first option, you can reverse them....
Read more >
Pure CSS: Accessible Checkboxes and Radios Buttons
If you are reading this article, you know that adding custom styles to default checkboxes and radio buttons using just CSS is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found