Examples of editor with auto-complete fields

Examples of editor with auto-complete fields

kevingillkevingill Posts: 2Questions: 0Answers: 0
edited February 2013 in Editor
Are there any examples of using autocomplete fields in the Editor?

Thanks,

Kevin

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi Kevin,

    Sent you a PM about this :-)

    Allan
  • kevingillkevingill Posts: 2Questions: 0Answers: 0
    Thanks for the info Allan.

    I found when I put the work in that this was very easy to achieve.
    I am using django-autocomplete-light as the backend.

    For the record, Here is my version if anyone is doing this in the future...

    [code]



    $.fn.DataTable.Editor.fieldTypes.autocomplete_text = $.extend( true, {}, $.fn.DataTable.Editor.models.fieldType, {
    "create": function ( conf ) {
    var that = this;
    conf._enabled = true;

    /* Mandatory Parameters */
    var fieldname = 'act' + conf['name'];
    var fieldid = conf['id'];
    var url = conf["url"];

    /* Optional Parameters */
    var placeholder = 'value ...';
    var bootstrap = 'normal';
    var selector = '[data-value]';

    if ('placeholder' in conf) { placeholder = conf["placeholder"];}
    if ('bootstrap' in conf) { bootstrap = conf['bootstrap'];}
    if ('selector' in conf) { selector= conf['selector'];}

    var widget = $('');

    window.yourlabs.Widget(widget);

    conf._input = widget[0];
    return conf._input;
    },
    "get": function ( conf ) {
    if ( ! conf._enabled ) {
    return;
    }
    return $(conf._input).val();
    },

    "set": function ( conf, val ) {
    if ( ! conf._enabled ) {
    return;
    }
    $(conf._input).val(val);
    },

    "enable": function ( conf ) {
    conf._enabled = true;
    $(conf._input).removeClass(' disabled ');
    },

    "disable": function ( conf ) {
    conf._enabled = false;
    $(conf._input).addClass(' disabled ');
    }
    } );

    [/code]

    Then I configure the field...

    [code]

    "fields": [ {
    ...
    }, {
    "label": "Track Title:",
    "name": 1,
    "type": "autocomplete_text",
    "url": "/rmmanuallog/autocomplete/ProgrammeName/",
    "placeholder": "track title ..."
    }, {
    [/code]

    There was a conflict between the django-autocomplete-light and the datatables editor logic. I had to disable this line in the django-autocomplete-light code...

    [code]
    $.ajaxSettings.traditional = true
    [/code]
This discussion has been closed.