Adding custom JS to widget designer? Dropdown SelectedValue incorrect in designer load.
I submitted this to telerik support, but I figured I'd also ask the community (plus hoping this would be useful to others, too)...
I have a custom widget that I created a while ago. I added a widget designer recently using SF Thunder (via add designer to existing widget option). This seems to have worked fine and my widget designer loads and works fine.
Now, I would like to add some custom javascript for the designer. For example, I have a dropdown menu and two "div" elements (this is all in the designer ASCX itself). When the user selects value1 in dropdown I want to show div1 and hide div2. When user selects value2 in dropdown, I want to hide div1 and show div2. I know how to do this with some basic jQuery but I'm not sure WHERE in the auto-generated designer JS file i should add this, and which syntax to use. That would be my first question.
For example, I'm used to doing something like this:
$(document).ready(function () $("#MyDropdown").change(function () if ($(this).val() == "value1") $("#div1").show(); $("#div2").hide(); else if ($(this).val() == "value2") $("#div1").hide(); $("#div2").show(); ););$(document).ready(function () /* --------------------- Startup scripts: ------------------------------- */ var selectedValue = $("#MyDropdown").val(); if (selectedValue== "value1") $("#div1").show(); $("#div2").hide(); else if (selectedValue == "value2") $("#div1").hide(); $("#div2").show(); /* --------------------- Event handlers: ------------------------------- */ $("#MyDropdown").change(function () if ($(this).val() == "value1") $("#div1").show(); $("#div2").hide(); else if ($(this).val() == "value2") $("#div1").hide(); $("#div2").show(); ); );I believe I've solved this. For the startup/initialization scripts, instead of doing this (BAD):
$(document).ready(function () var selectedValue = $("#MyDropdown").val(); if (selectedValue== "value1") $("#div1").show(); $("#div2").hide(); else if (selectedValue == "value2") $("#div1").hide(); $("#div2").show(); );$(window).load(function () var selectedValue = $("#MyDropdown").val(); if (selectedValue== "value1") $("#div1").show(); $("#div2").hide(); else if (selectedValue == "value2") $("#div1").hide(); $("#div2").show(); );/* --------------------- Event handlers: ----------------------- */$(document).ready(function () $("#MyDropdown").change(function () if ($(this).val() == "value1") $("#div1").show(); $("#div2").hide(); else if ($(this).val() == "value2") $("#div1").hide(); $("#div2").show(); ););/* --------------------- Startup/initialization: ----------------------- */$(window).load(function () var selectedValue = $("#MyDropdown").val(); if (selectedValue== "value1") $("#div1").show(); $("#div2").hide(); else if (selectedValue == "value2") $("#div1").hide(); $("#div2").show(); );Hi Marko,
This is great input! Thank you for sharing your observations with the community.
All the best,