HTML type color

HTML type color

teriblusteriblus Posts: 4Questions: 1Answers: 0

Hi,

Can editor support <input type='color'/> html form control ?
I tried to add the following field without success : {label: "Couleur :", name: "color", type:'color'}

Can you point me to a quick and easy solution to acheive a color picker inside editor ?

Thank you,
Tristan

This question has an accepted answers - jump to answer

Answers

  • teriblusteriblus Posts: 4Questions: 1Answers: 0

    I'm trying to have a form control like this one : http://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_color

  • teriblusteriblus Posts: 4Questions: 1Answers: 0

    I made a plugin for that :

    '''
    (function (factory) {
    if (typeof define === 'function' && define.amd) {
    // AMD
    define(['jquery', 'datatables', 'datatables-editor'], factory);
    }
    else if (typeof exports === 'object') {
    // Node / CommonJS
    module.exports = function ($, dt) {
    if (!$) {
    $ = require('jquery');
    }
    factory($, dt || $.fn.dataTable || require('datatables'));
    };
    }
    else if (jQuery) {
    // Browser standard
    factory(jQuery, jQuery.fn.dataTable);
    }
    }(function ($, DataTable) {
    'use strict';

    if (!DataTable.ext.editorFields) {
        DataTable.ext.editorFields = {};
    }
    
    var _fieldTypes = DataTable.Editor ?
        DataTable.Editor.fieldTypes :
        DataTable.ext.editorFields;
    
    
    _fieldTypes.color = {
        create: function (conf) {
            conf._input = $('<input/>')
                .attr($.extend({
                    id: conf.id,
                    type: 'color'
                }, conf.attr || {}));
    
    
            return conf._input[0];
        },
    
        get: function (conf) {
            return conf._input.val();
        },
    
        set: function (conf, val) {
            conf._input.val(val)
        },
    
        enable: function (conf) {
            conf._input.prop('disabled', true);
        },
    
        disable: function (conf) {
            conf._input.prop('disabled', false);
        }
    };
    

    }));

    '''

  • fernaogfernaog Posts: 1Questions: 0Answers: 0

    Thanks, this helped me.

  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin
    Answer ✓

    You can use the attr option of the input type:

    {
      label: "Couleur :",
      name: "color",
      attr: {
        type:'color'
      }
    }
    

    Allan

This discussion has been closed.