Splunk Dev

How to add a label to a splunkjs CheckboxView?

bhawkins1
Communicator

I want to add a text label next to a splunkjs CheckboxView that displays some text so the user knows what the checkbox does.

The example at http://dev.splunk.com/view/SP-CAAAEVJ uses label: "Check me",, but this doesn't actually do anything.

That's consistent with the component ref for checkboxview - http://docs.splunk.com/DocumentationStatic/WebFramework/1.4/compref_checkbox.html

Which doesn't have a "label" property.

How can one add a label to a CheckboxView?

0 Karma
1 Solution

rjthibod
Champion

You are correct in that the class definition does not include it.

I had a similar issue with the TextInputView and TimeRangeView classes in my own app.

I got around this by prepending a raw html <label> element to the objects.

For example,

// Instantiate components
var mycheckboxview = new CheckboxView({
  id: "mycheckboxview",
  default: false,
  el: $("#mycheckboxview")
}).render();

$('#mycheckboxview').prepend('<label>YOUR LABEL</label>');

View solution in original post

rjthibod
Champion

You are correct in that the class definition does not include it.

I had a similar issue with the TextInputView and TimeRangeView classes in my own app.

I got around this by prepending a raw html <label> element to the objects.

For example,

// Instantiate components
var mycheckboxview = new CheckboxView({
  id: "mycheckboxview",
  default: false,
  el: $("#mycheckboxview")
}).render();

$('#mycheckboxview').prepend('<label>YOUR LABEL</label>');

bhawkins1
Communicator

Thanks for the response. It turns out that CheckboxView is stylized differently than CheckboxGroupView, so I will use CheckboxGroupView throughout my app.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...