Thursday, September 22, 2016

Accessing Telerik RadComboBoxes via jQuery

Yes yes, I know, Telerik is terrible and it creates an incredible amount of just unnecessary markup and the controls don't work very well in the wild, even though the demos seem so easy and simple!

But sometimes you just need to use a RadComboBox because you need a multi-dropdown list with checkboxes inside, and you don't want to roll your own. Then you need to use jQuery to manually open them in some cases, because you have a non-mobile-friendly old version of Telerik that you can't update for fear of breaking multiple other sites that all use the same assemblies. You suddenly understand why some corporations still run Windows 7 even though Microsoft is trying as hard as it can to disavow it and IE. It's just too hard, time-consuming, and expensive. And you just need it done.

After trying unsuccessfully to get the danged dropdowns to open by writing a bit of JS that inexplicably find the dropdowns non-existent, and getting a lot of "null" returns for said dropdowns, you finally stumble upon developer googling gold.

Telerik has its own jQuery library, which enables you to access and manipulate their controls via javascript. What the frig?

First, add the references to the jQuery library on your page:
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" >
   <Scripts>
       <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
       <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
   </Scripts>
</telerik:RadScriptManager> 

Now, lets say you have the following RadComboBox:
<telerik:RadComboBox runat="server" ID="rcbEveryoneLikesOptions" AutoPostBack="True"></telerik:RadComboBox>

To get it via jQuery, use this syntax:
var rcbEveryoneLikesOptions = $find("<%=rcbEveryoneLikesOptions.ClientID %>");

Then you can do fun things with it like dynamically open it:
rcbEveryoneLikesOptions.showDropDown();

You can find all the other allowable events and more detailed info here:
Using jQuery with Telerik
RadComboBox Object jQuery fun
Tuesday, September 13, 2016

Deleting endlessly nested node_modules directories on Windows



If you've ever tried to delete an npm project on Windows, you've probably had this error window pop up. Trying various things like Shift-Del to permanently delete, or using 7Zip to delete, or using the command prompt rmdir command just doesn't work. Argh!

Windows just can't handle these incredibly long pathnames for nested node_modules folders. Fortunately since the problem is an npm issue, there is an npm solution.

The best one I've found is rimraf. It's an npm package that is designed to delete directories. If you haven't used npm before, don't fret. You do need to use the command prompt, but if you type in the following commands it should be straightforward.

Install the npm rimraf package globally on your computer. The "-g" global ensures that you can run rimraf from any directory.
npm install rimraf -g

Then open a command window in the parent directory of the directory you want to wipe off the face of the earth.

Type in the following and you should be free of the nested terror!
rimraf node_modules

Celebrate.


Saturday, September 3, 2016

Regex simplification tool

Regex strings are useful when validating form inputs-- making sure people enter in their names and phone numbers correctly when filling out forms. However, in its existing syntax, it can be quite a headache to implement. I confess that when I need a regex string, I just google whatever I'm looking for, copy, paste, and if it works I forget about it.

Here's a typical regex string:

/^(?:[0-9]|[a-z]|[\._%\+-])+(?:@)(?:[0-9]|[a-z]|[\.-])+(?:\.)[a-z]{2,}$/i

Not easily readable, right? Here's where SRL (Simple Regex Language) wants to save you time. This tool uses more human-friendly syntax to generate the regex string for you. You can use their online generator, or install their tool for your site.

Here is one example of an SRL string, which is quicker to compute:

begin with any of (digit, letter, one of "._%+-") once or more,
literally "@",
any of (digit, letter, one of ".-") once or more,
literally ".",
letter at least 2 times,
must end, case insensitive


I haven't tried it out yet, but next time I need a regex I will!