Toggle: Using the attributeName in the template
See original GitHub issueI’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:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve added the feedback to put the product team in the loop. I’m closing the issue for now.
I’ll leave this open for now because I can see the value