1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Bug with multiple ButtonSelectors ?

Bug with multiple ButtonSelectors ?

4 posts, 0 answered
  1. Pedro De Sousa
    Pedro De Sousa avatar
    4 posts
    Registered:
    24 Nov 2009
    18 Feb 2010
    Link to this post
    I have the following code fragment on a form:
    <ol>
      <li class="selector">
        <asp:Label AssociatedControlID="imageBox" runat="server" Text="Image" />
        <asp:TextBox ID="imageBox" runat="server" MaxLength="250" />
        <sfLib:ButtonSelector
         WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageEditorDialog.aspx"
         AssociatedControls="imageBox" ButtonText="Sélectionner" TemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx"
         runat="server" cssclass="pickerWrapper" />
      </li>
      <li class="selector">
        <asp:Label AssociatedControlID="cmsPagePathBox" runat="server" Text="Cms page path" />
        <asp:TextBox ID="cmsPagePathBox" runat="server" MaxLength="250" />
        <sfLib:ButtonSelector
         WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/PagesSelector.aspx"
         AssociatedControls="cmsPagePathBox" ButtonText="Sélectionner"
                                   ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/Libraries/Dialogs/ButtonSelector.ascx"
         runat="server" cssclass="pickerWrapper" />
      </li>
    </ol>
    Basically, it's two labels, textboxes and ButtonSelectors. I expect the user to choose an image for the first one, and a page for the second.

    If I comment out the second ButtonSelector, the first one works fine and you can select images such as:
    [Libraries]2e462d0b-5108-4383-8a19-96f08d08619a

    But if I uncomment the second ButtonSelector, the first one is broken and now selected images return full URLs, e.g.:
    http://localhost:1662/nestle-lvb/Libraries/Interviews/ester_blue_light.sflb.ashx

    Note that the second ButtonSelector works and produces links like this one:
    [Sitefinity]eb85fa79-62e4-4b00-b9ea-d10265f3eb07

    Is this a bug or am I doing something wrong?

    Thanks.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    18 Feb 2010
    Link to this post
    Hi Pedro De Sousa,

    The ButtonSelector does not work properly in the versions before Sitefinity 3.7 SP2. There are some bugs.
    However in 3.7 SP2 you should be able to use multiple selectors.

    Note that you need to change the OnClientClose function in ~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx as shown below

    function OnClientClose(sender, eventArgs) {
           if (sender.argument) {
               var title = '';
               var altText = '';
               var src = '';
               var width;
               var height;
               var unresolved;
     
               if (sender.argument.title)
                   title = sender.argument.title;
               if (sender.argument.altText)
                   altText = sender.argument.altText;
               if (sender.argument.src)
                   src = sender.argument.src;
               if (sender.argument.width && sender.argument.height) {
                   width = sender.argument.width;
                   height = sender.argument.height;
               }
               if (sender.argument.unresolved) {
                   unresolved = sender.argument.unresolved;
               }
               if (sender.argument.attributes && sender.argument.attributes["sfref"] != undefined) {
                   unresolved = sender.argument.attributes["sfref"].value;
               }
           
               if (sender.argument["src"] != null && sender.argument["src"] != undefined) {
                   unresolved = sender.argument["src"];
               }
     
               selectedItem = new SelectedItem(src, altText, title, width, height, unresolved);
     
               if (typeof (sfUseResolvedUrl) == 'undefined') {
                   sfUseResolvedUrl = true;
               }
     
               for (i = 0; i < assignedControls.length; i++) {
                   if (assignedControls[i] != '') {
                       var element = document.getElementById(assignedControls[i]);
                       if (element.src) {
                           if (!(/selectedImage/.test(element.id)) && !(/uploadedImage/.test(element.id))) {
                               element.src = sender.argument.src;
                           }
                           else {
                               element.src = sender.argument.src + '?width=300&height=300&decreaseOnly=true';
                           }
                       }
                       else if (typeof (element.value) != 'undefined' && element.value != null) {
                           if (!sfUseResolvedUrl && (/selectedValue/.test(element.id))) {
                               element.value = unresolved;
                           }
                           else {
                               element.value = unresolved;
                           }
                       }
                       else if (typeof (element.href) != 'undefined') {
                           element.href = sender.argument.src;
                       }
                       else if (typeof (element.innerHTML) != 'undefined') {
                           element.innerHTML = sender.argument.src;
                       }
                   }
               }
           }
       }

    otherwise you may have some problems with the value returned from the second - page selector. Generally there are not attributes to the argument and you need to get the ID from the src argument


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Pedro De Sousa
    Pedro De Sousa avatar
    4 posts
    Registered:
    24 Nov 2009
    19 Feb 2010
    Link to this post
    Thanks for your answer. Unfortunately, even after upgrading to 3.7 SP2 and pasting the code you wrote it still doesn't work.

    I managed to fix the issue myself. The javascript code I've used is the following one:
    function OnClientClose(sender, eventArgs) {
      if (sender.argument) {
        var title = '';
        var altText = '';
        var src = '';
        var width;
        var height;
        var unresolved;
      
        if (sender.argument.title)
          title = sender.argument.title;
        if (sender.argument.altText)
          altText = sender.argument.altText;
        if (sender.argument.src)
          unresolved = src = sender.argument.src;
        if (sender.argument.width && sender.argument.height) {
          width = sender.argument.width;
          height = sender.argument.height;
        }
        if (sender.argument.unresolved) {
          unresolved = sender.argument.unresolved;
        }
        else if (sender.argument.attributes && sender.argument.attributes["sfref"] != undefined) {
          unresolved = sender.argument.attributes["sfref"].value;
        }
        selectedItem = new SelectedItem(src, altText, title, width, height, unresolved);
      
        if (typeof (sfUseResolvedUrl) == 'undefined') {
          sfUseResolvedUrl = true;
        }
      
        for (i = 0; i < assignedControls.length; i++) {
          if (assignedControls[i] != '') {
            var element = document.getElementById(assignedControls[i]);
            if (element.src) {
              if (!(/selectedImage/.test(element.id)) && !(/uploadedImage/.test(element.id))) {
                element.src = sender.argument.src;
              }
              else {
                element.src = sender.argument.src + '?width=300&height=300&decreaseOnly=true';
              }
            }
            else if (typeof (element.value) != 'undefined' && element.value != null) {
              if (!sfUseResolvedUrl && (/selectedValue/.test(element.id))) {
                element.value = unresolved;
              }
              else {
                element.value = unresolved;
              }
            }
            else if (typeof (element.href) != 'undefined') {
              element.href = sender.argument.src;
            }
            else if (typeof (element.innerHTML) != 'undefined') {
              element.innerHTML = sender.argument.src;
            }
          }
        }
      }
    }

    I really hope the next release would fix that, as this kind of changes to Sitefinity code makes it very difficult to upgrade.

    Regards,
    Pedro
  4. bemara57
    bemara57 avatar
    135 posts
    Registered:
    27 Mar 2008
    20 May 2010
    Link to this post
    @Pedro your fix resolved the bug. Not sure of the implications elsewhere in the system, but your two fixes is great! Thanks!!
Register for webinar
4 posts, 0 answered