Proper method to access field options

Proper method to access field options

redbaronredbaron Posts: 12Questions: 6Answers: 1

I am working on a custom plugin for a field type, and want to detect an event that this field will generate.

Editor is declared such as:

   var editor = new $.fn.dataTable.Editor({
            ajax: "edit?cmd=ajax",
            table: "#master-list",
            display: onPageDisplay(formContainer),
            template: "#master-editor-form",
            idSrc: "id",
            fields: [{
                label: "Name:",
                name: "title"
            }, {
                label: "Images:",
                name: "fileupload1",
                type: "dropzone"
           }
           ]
        }
    );

the custom field type "dropzone" has an event I want to catch called "complete". In order to do this, I need to access the options for the field to get my custom variable _dropzone, where the object is stored. This code does work:

      editor.field("fileupload1").s.opts._dropzone.on('complete', function (file) {
               alert("complete");
            });

I feel that I am not properly accessing the options, and want to know if there is a proper way to accomplish the same task?

This question has an accepted answers - jump to answer

Answers

  • redbaronredbaron Posts: 12Questions: 6Answers: 1

    i did find a solution for my plugin, but this doesn't necessarily answer the original question. it appears that the opts does not have a direct access method. I created a function for my plugin to return the object I was after

    // Get the Dropzone instance
      _fieldTypes.dropzone = {
      // ..snip...
            dropzone: function (conf) {
                return conf._dropzone;
            }
    };
    

    this allows me to use the following now:

    editor.field("fileupload1").dropzone().on('complete', function (file) {
    alert("complete");
    });
    

    I assume that the only way to access this data would be the s.opts. method if another method does not exist.

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    You are correct - your dropzone function is the way I would implement that as well (and have done in some of the plug-ins), but there is no direct access method for the field options. That is something that shouldn't really be accessed outside of the field plug-in code - at least that's how I've been viewing it.

    Allan

This discussion has been closed.