Require Image Browser Alternate Text

2 posts, 0 answers
  1. Christopher
    Christopher avatar
    1 posts
    Member since:
    Jan 2016

    Posted 06 Sep Link to this post

    Is there a way to make the "Alternate Text" value required for the Image Browser.  I have found a way to implement this functionality for the Insert button, but I cannot find a way for it to work for double-clicking the image.  Note, I do consider the Insert button "solution" a hack and would prefer to implement a better solution if one exists.

    // Editor definition
    element.kendoEditor({
      execute: handlers_editorExecute,
      imageBrowser: {
        apply: handlers_editorImageBrowserApply,
      }
    });
         
    // This does not work for double-clicking the image because the image is inserted regardless of the return value
    handlers_editorImageBrowserApply: function (e) {
      var imageBrowser = $(".k-imagebrowser").data("kendoImageBrowser"); 
     
      if (imageBrowser.value() != "") {
        if ($(".k-filebrowser-dialog #k-editor-image-title").val() == "") {
          alert("Alternate text is required.");
          return false;
        }
      }
    },
    // This does work for clicking the Insert button and the apply function is not defined, but feels like a hack
    handlers_editorExecute: function (e) {
      if (e.name == "insertimage") {
        setTimeout(function () {
          var insertButton = $(".k-filebrowser-dialog .k-dialog-insert");
          insertButton.unbind("click");
          insertButton.click(function () {
            var imageBrowser = $(".k-imagebrowser").data("kendoImageBrowser");
            if (imageBrowser.value() != "") {
              if ($(".k-filebrowser-dialog #k-editor-image-title").val() == "") {
                alert("Alternate text is required.");
                return false;
              }
            }
            imageBrowser.trigger("apply");
          });
        });
      }
    },
  2. Ianko
    Admin
    Ianko avatar
    1729 posts

    Posted 08 Sep Link to this post

    Hello Christopher,

    I am afraid there is no more suitable solution for the case. The code you have implemented seems to work properly as per to this requirement. 

    What I can suggest you is to post a feedback item in the Kendo feedback portal and request the FileBrowser and ImageBrowser to be refactored so that they are more flexible and customizable. Or just request an option for the alt text to be made required. 

    Regards,
    Ianko
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top