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.

Toggle: Using the attributeName in the template

See original GitHub issue

I’m trying to add use the unique attributeName for my Toggle in the custom template (to link the label to the input) but I can’t seem to find any way to access it within the template.

var toggleTemplate = '<div class="be-checkbox">' +
    '<input id="toggle_{{attributeName}}" type="checkbox" class="{{cssClasses.checkbox}}" value="{{name}}" {{#isRefined}}checked{{/isRefined}}>' +
    '<label for="toggle_{{attributeName}}">{{name}} <span class="{{cssClasses.count}}">{{#helpers.formatNumber}}{{count}}{{/helpers.formatNumber}}</span></label>' +
    '</div>';
search.addWidget(
    toggle({
        container: document.querySelector('#type-dinner-container'),
        attributeName: 'type_dinner',
        label: 'Dinner',
        autoHideContainer: false,
        templates: {
            item: toggleTemplate
        }
    })
);

Required: unique identifier for this element, using the label isn’t ideal since it can include special characters and spaces.

A (not ideal) solution

I can use transformData to do some less than ideal magic to achieve a similar result (excluding special characters in this case)

transformData: function (item)
{
    item.attributeName = item.name.replace(/ /g,"_").toLowerCase();
    return item;
},

However since I have 12 toggles, adding this to every toggle widget object statement is not ideal as you can imagine…

Perhaps the attributeName should be passed into the render method?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bobylitocommented, Jun 29, 2018

I’ve added the feedback to put the product team in the loop. I’m closing the issue for now.

1reaction
Haroenvcommented, Feb 16, 2018

I’ll leave this open for now because I can see the value

Read more comments on GitHub >

github_iconTop Results From Across the Web

Element.toggleAttribute() - Web APIs | MDN
A string specifying the name of the attribute to be toggled. The attribute name is automatically converted to all lower-case when ...
Read more >
Element.toggleAttribute()
The toggleAttribute() method of the Element interface toggles a Boolean attribute (removing it if it is present and adding it if it is...
Read more >
HTML | DOM toggleAttribute() Method - GeeksforGeeks
The toggleAttribute() method of the element interface toggles a Boolean attribute on the given element. Attributes of an element can be changed ...
Read more >
2.2.44 toggleButton (Toggle Button Inside of a Split Button)
This element specifies a toggle button control that is part of a split button control. The visible and getVisible attributes are not ...
Read more >
Attribute name not allowed on element div at this point
I found some entry from: Markup Validation Error: "Attribute name not allowed on element at this point" error #HTML5. Just in case you...
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