FileManager - Custom Command Works Once, Fails After

1 Answer 75 Views
FileManager
Matt
Top achievements
Rank 1
Matt asked on 12 May 2023, 07:46 PM | edited on 12 May 2023, 07:55 PM

I am running the current version, 2023.1.425.

The control is actually first created through asp.net core MVC, however I'm using the CustomCommand method as such. Please note the window is already initialized prior to this. Upon the first use of my custom "Tags" context menu, the window opens and I'm able to carry out operations as expected. After closing the window, and attempting to open it again, I get an error in the browser console.

var filemanagerNS = kendo.ui.filemanager;
        filemanagerNS.commands.MyCustomCommand = filemanagerNS.FileManagerCommand.extend({
          exec: function(){
                 var FileIDs = Array();
                 var i = $('#filemanager').getKendoFileManager().getSelected();
                 $(i).each(function(){
                     if (!this.isDirectory)
                        FileIDs.push(this.ID);
                 });

                if (FileIDs.length > 0) {
                    // we'd call up our modal here populated with some kind of tag manager
                    $.post( "/Tags", { "FileIDs": FileIDs }, function( data ) {
                        $("#frmmodal").html(data).data("kendoWindow").open();
                    });
                 }
          }
        });


This works the first time, but attempting to open the window again results in the following error:

Uncaught TypeError: n.filemanager.commands[t] is not a constructor
    at init.executeCommand (kendo.all.js:318819:21)
    at init.trigger (kendo.all.js:318819:21)
    at init.action (kendo.all.js:318819:21)
    at init._onSelect (kendo.all.js:318819:21)
    at init.trigger (kendo.all.js:318819:21)
    at init._triggerEvent (kendo.all.js:318819:21)
    at init._triggerSelect (kendo.all.js:318819:21)
    at init._click (kendo.all.js:318819:21)
    at HTMLUListElement.dispatch (jquery.min.js:3:12445)
    at r.handle (jquery.min.js:3:9174)

 

As a result, the component stops functioning entirely, not just the context menu -> window method that seems to be causing this.

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 17 May 2023, 11:42 AM

Hello, Matt,

The approach you have shared is the correct one to set a custom command. I have tested it in this Dojo example and I can see no errors, meaning that the problem comes from this line:

if (FileIDs.length > 0) {
              // we'd call up our modal here populated with some kind of tag manager
              $.post( "/Tags", { "FileIDs": FileIDs }, function( data ) {
                $("#frmmodal").html(data).data("kendoWindow").open();
              });
            }

I would suggest debugging the code and what is happening on the remote end point.

Let me know if the information above would be useful.

Regards,
Martin
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Matt
Top achievements
Rank 1
commented on 17 May 2023, 05:54 PM | edited

Edit:

You were right, after all, sorry! The function on the backend was returning a fully rendered page instead of the HTML partial.

 

Thank you!

Martin
Telerik team
commented on 22 May 2023, 11:28 AM

I am happy to hear you managed to sort it out!
Tags
FileManager
Asked by
Matt
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or