Smart UI Components & Libraries – Grid, Scheduler, Gantt, Kanban for Angular, React, Next.js, Vue, Blazor, JavaScript › Forums › General Discussions › Menu & Tree › Adding checkbox menu items
Tagged: angular menu, checkbox menu, custom element, menu, react menu, smart elements, smart framework, smart menu, web component, web components
- This topic has 4 replies, 2 voices, and was last updated 5 years, 5 months ago by tundekeller94. 
- 
		AuthorPosts
- 
		
			
				
May 8, 2020 at 2:56 pm #100739tundekeller94 MemberIf I have a menu to which I’d like to add items via JavaScript, then how can enable checkboxes? 
 <smart-menu id=”menu”></smart-menu>
 <button id=”ads” onclick=”AddItems()”>Add items</button>
 function AddItems() {
 let menu = document.getElementById(‘menu’);
 let subMenu = document.createElement(‘smart-menu-items-group’);
 subMenu.innerHTML = ‘Item 0’
 menu.addItem(subMenu)
 let newItem = document.createElement(‘smart-menu-item’);
 newItem.innerHTML = ‘Item 1’
 menu.addItem(newItem , “0”)
 }
 I have tried applying:
 subMenu.setAttribute(“checkable”, “”)
 subMenu.setAttribute(“check-mode”, “checkbox”)
 newItem.setAttribute(“checked”, “”)
 But that did not work. Is there a way to add checkbox enabled items dynamically?May 11, 2020 at 8:17 am #100741Hristofor MemberHi Tünde Keller, 
 In order to enable ‘checkbox’ mode or other dynamically for a specificSmartMenuItemsGroup, simply set thecheckableproperty to the target SmartMenuItemsGroup. CheckBox mode is set as the defaultcheckMode. You can change that as well if you need. For example in your code:function AddItems() { ... let subMenu = document.createElement(‘smart-menu-items-group’); subMenu.checkable = true; subMenu.innerHTML = ‘Item 0’ ... }SmartHTML elements are custom elements and as such they have properties that can be applied dynamically or statically. So the following code is incorrect: subMenu.setAttribute(“checkable”, “”) subMenu.setAttribute(“check-mode”, “checkbox”) newItem.setAttribute(“checked”, “”)In order to set those properties to the SubMenu or the menu you need to set them directly as properties. See the API for additional information. 
 Best Regards,
 Christopher
 Smart HTML Elements Team
 https://www.htmlelements.comMay 11, 2020 at 10:57 am #100744tundekeller94 MemberHi Christopher, 
 Interesting, it still does not want to work. It’s possible that I’m misunderstanding something so I created a codepen to show what I’m trying to do: https://codepen.io/t-nde-keller/pen/abvqXEoMay 11, 2020 at 11:53 am #100746Hristofor MemberHi Tünde Keller, 
 You also need to setcheckboxeson the Menu Custom element as well. As it says in the API . We also have a : Demo with Checkbox Menu.
 Best Regards,
 Christopher
 Smart HTML Elements Team
 https://www.htmlelements.comMay 11, 2020 at 1:48 pm #100748tundekeller94 MemberYou are right, I have overlooked that property. Thank you, now everything is fine! 
- 
		AuthorPosts
- You must be logged in to reply to this topic.