Editor: UploadMany File Rendering

Editor: UploadMany File Rendering

rf1234rf1234 Posts: 2,986Questions: 87Answers: 421

I use this code in my Javascript Editor instance field definitions:

}, {
    label: lang === 'de' ? 'Dokumentation:' : 'Documentation:',
    name: "file[].id",
    type: "uploadMany",
    display: function (fileId, counter) {
        var fileNameExt = contractEditor.file('file', fileId).name;
        if (fileNameExt.substr(0,9) === 'interface') {
            return '';
        }                
        return fileNameExt;
    },
    dragDropText: dragDropText,
    uploadText: uploadText,
    noFileText: noFileText,
    processingText: processingText,
    fileReadText: fileReadText

Files with names starting with "interface" shouldn't be displayed in the Editor popup because I don't want the users to be able to delete them. This doesn't really work because there still is this little button to delete the file in Editor even though the label isn't there because I set it to blank. I tried to return null or false but that didn't work either.

Is there any solution for this?

This is what it looks like with the little delete button for the unlabeled file at the right hand side.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,986Questions: 87Answers: 421

    I found a provisional solution for the problem but it is not very nice. I save the counter values of the empty file names and "onOpen" of the Editor form I hide those buttons using plain jQuery.

    This is what I added to the "display" function of the Editor field definition:

    }, {
        label: lang === 'de' ? 'Dokumentation:' : 'Documentation:',
        name: "file[].id",
        type: "uploadMany",
        display: function (fileId, counter) {
            if ( counter === 0 ) {
                interfaceCounter = [];
            }
            var fileNameExt = rfpGovEditor.file( 'file', fileId ).name;
            var renderName = renderFilesEditor(fileNameExt);
            if (renderName === '') {
                interfaceCounter.push(counter);
            }
            return renderName;
        },
    

    And this is the jQuery that is being executed "onOpen" of the Editor form:

    $('button.remove[data-idx]').removeClass('hidden');
    var i;
    for (i=0; i < interfaceCounter.length; i++) {
        $('button.remove[data-idx="'+interfaceCounter[i]+'"]').addClass('hidden');
    }
    

    @allan, Is there a better solution using the api?

  • rf1234rf1234 Posts: 2,986Questions: 87Answers: 421

    @allan, @colin,
    would you take a look please.
    Roland

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    I fear that the only better solution would be to modify the code to allow a callback to see if the option should be displayed or not in the list of files. That isn't something that I'd considered as a possibility before I'm afraid.

    Allan

This discussion has been closed.