Autocomplete

Autocomplete

Alexandr45Alexandr45 Posts: 30Questions: 1Answers: 3

How do I set placeholder for the Autocomplete field type ? JQuery UI plugin is enabled.

Replies

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406

    try attr like this. if that doesn't work you can try to add the placehoder to opts.

    new $.fn.dataTable.Editor( {
     "ajax": "php/dates.php",
     "table": "#example",
     "fields": [ {
         "label": "Genres:",
         "name": "genre",
         attr: {
             placeholder: "blablabla"
         },
         "type": "autoComplete",
         "opts": {
           "source": [
             // array of genres...
           ],
           placeholder: "blablabla" //if attr not working
         }
       },
       // additional fields...
     ]
    } );
    
  • Alexandr45Alexandr45 Posts: 30Questions: 1Answers: 3
    edited May 2020

    Unfortunately, neither option works. Everything works with other types of fields. Doesn't work only with autoComplete.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    It might be worth trying Allan's suggestion at the of this thread, that might do the trick,

    Colin

  • Alexandr45Alexandr45 Posts: 30Questions: 1Answers: 3

    Thanks!!! It really works.

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406
    edited May 2020

    Great you got it working. My problem is that I keep forgetting what I implemented successfully before ... :neutral:

    https://editor.datatables.net/reference/api/field().input() is good for many things.

    I used this previously many times when I needed to dynamically change the placeholder to be matching the respective field type. This code is inside an Editor event handler:

    editor
    .on('open', function (e, mode, action) {
        var that = this;        
        var fieldType = that.val('filtr_field_type');
        that.field('contract_has_filtr.value').input()
            .attr('placeholder', $.grep(fieldTypeOptions,                 
               function(obj){return obj.value == fieldType;})[0].label);
            switch (fieldType) {
                case '1': //numeric signed, 0 decimal places
                    that.field('contract_has_filtr.value').input()
                        .addClass(numFilterMaskNoDecPlaces); 
                    maskNumFilter();
                    break;
                case '2': //numeric signed, 5 decimal places
                    that.field('contract_has_filtr.value').input()
                        .addClass(numFilterMask); 
                    maskNumFilter();
                    break;
                ......
                default: //string: no mask
                    break;
            }
    }); 
    
  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    My problem is that I keep forgetting what I implemented successfully before ... :neutral:

    ...and where to find it. And why it works. And... :neutral:

This discussion has been closed.