Disabled Editor field with plugin

Disabled Editor field with plugin

egberteegberte Posts: 13Questions: 1Answers: 0
edited June 2014 in Editor

I have a DatetimePicker using a plug in:

var editor_exportsets = new $.fn.dataTable.Editor({
fields: [ {
            label: "Date/Time:",
            name: "schedule.onceDateTime",
            type: "datetime",
            labelInfo: "(YYYY-MM-DD HH:mm)",
            opts: {
                pick12HourFormat: false,
                useSeconds: false,
                format: 'YYYY-MM-DD HH:mm'
}

I want to disable it when the form is busy. I tried this but it didn't work:

editor_exportsets.disable(['schedule.onceDateTime' ]);

The datepicker has its own disabled function but I'm not sure how to deploy it.
$('#datetimepicker3').data("DateTimePicker").disable();

Do i add a "disable" and "enable" function in the plug-in editor.datetimepicker.js?

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

    conf._input = $(
            '<DIV class="input-group date" id="'+conf.id+'">'+
                '<INPUT type="text" class="form-control" />'+
                '<SPAN class="input-group-addon"><SPAN class="glyphicon"></SPAN>'+
                '</SPAN>'+
            '</DIV>'
        )
        .datetimepicker( $.extend( {}, conf.opts ) );

    return conf._input[0];
},

"get": function ( conf ) {
return conf._input.find('input').val();
},

 "set": function ( conf, val ) {
conf._input.find('input').val( val );
 },

// Non-standard Editor methods - custom to this plug-in. Return the jquery
// object for the datetimepicker instance so methods can be called directly
inst: function ( conf ) {
    return conf._input;
}
} );

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi,

    What you should be able to do is:

    var picker = editor_exportsets.field( 'schedule.onceDateTime' ).inst();
    picker.disable();
    

    The inst() method will return the stored _input parameter from the field type plug-in here - the jQuery object for the date time picker.

    Alternative you could use:

    $( '#datetimepicker3', editor_exportsets.field( 'schedule.onceDateTime' ).node() )
        .data("DateTimePicker").disable();
    

    (assuming that id is correct).

    Regards,
    Allan

  • egberteegberte Posts: 13Questions: 1Answers: 0
    edited June 2014

    Almost worked but got me further along. This was what did it:

    var onceDateTimepicker = editor_exportsets.field('schedule.onceDateTime').inst();
    
    onceDateTimepicker.data("DateTimePicker").disable();
    

    the inst method was key so thanks for suggesting it.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Great thanks - I'll update the plug-in to return the DateTimePicker data.

    Allan

This discussion has been closed.