Sorting for / view rules in the designer.

  • 18 August 2023
  • 2 replies
  • 53 views

Userlevel 3
Badge +9

Are you as perplexed as me as to why the rules for forms and views are still not sorted alphabetically in the rules designer (see also Service Instance definitions when creating SmartObject methods), do you get fed up hunting for the rules constantly?

When you have the form / view open in the K2 designer, press F12 for the browser developer tools, paste the below code in to the console and hit return.

$('#pgRuleList').find('.toolbar-wrapper').append('<div class="toolbar-divider" id=""></div><a href="javascript:;" onclick="(function (){ const rules = Array.from(document.querySelectorAll(\'.input-control-group\')); rules.forEach(ul => { const rule = Array.from(ul.querySelectorAll(\'li\')); rule.sort((a, b) => { const textA = a.textContent.trim(); const textB = b.textContent.trim(); return textA.localeCompare(textB); }); ul.innerHTML = \'\'; rule.forEach(li => ul.appendChild(li));});})();" tabindex="0" class="toolbar-button filter" id="pgSortRules" title="Sort Rules"><span class="button-l"></span><span class="button-c"><span class="button-icon"></span><span class="button-text">Sort Rules</span></span><span class="button-r"></span></a>')

This will add a button to the Rules tab that will sort them for you when you press it.

 

Cheers


2 replies

Userlevel 3
Badge +9

Can a mod add an m to ‘for’ in the title for me please - cheers.

Userlevel 5
Badge +13

Very good idea! Thank you for sharing this.

Reply