Activate or deactivate a field

Activate or deactivate a field

recibeTodorecibeTodo Posts: 7Questions: 2Answers: 1

Best regard.
I need a field to be disabled when another field has been selected. For example, two date type fields, when the date of one is selected, the date in the other can not be selected. I appreciate the help.

Answers

  • kthorngrenkthorngren Posts: 21,310Questions: 26Answers: 4,948

    I'm assuming you are talking about Editor fields. If so then maybe the dependent() API will help you.
    https://editor.datatables.net/reference/api/dependent()

    Kevin

  • recibeTodorecibeTodo Posts: 7Questions: 2Answers: 1

    Hello Kevin, thank you for responding, I am working with this editor https://editor.datatables.net/examples/inline-editing/submitButton.html what you sent me looks very good but I do not know how to implement it

  • recibeTodorecibeTodo Posts: 7Questions: 2Answers: 1
    edited June 2018

    I found this answer from Allan where he says that it is not possible to use this API with Inline editing with dependent. https://datatables.net/forums/discussion/46020/inline-editing-with-dependent.

    I would appreciate any other suggestion :smile:

  • kthorngrenkthorngren Posts: 21,310Questions: 26Answers: 4,948

    I have a table with inline editing that I allow editing of specific fields based on other field values in the row. In the below example I active inline editing if certain conditions are true (removed the non-relevant code):

        // Activate an inline edit on click of a table cell
        $('#main-table').on( 'click', 'tbody td:not(:first-child)', function (e) {
    
        <code to gather graphFilter and graphSource information>        
    
        if ((graphFilter && graphSource === title) || !graphFilter) {
                editor.inline( this, {
                    onBlur: 'submit',
            } );
           }
        } );
    

    HTH,
    Kevin

  • allanallan Posts: 63,480Questions: 1Answers: 10,467 Site admin

    This is correct, since only a single field can be shown as editable at a time while inline editing, you can't control other fields. It would be effectively redundant. You could use bubble() to show multiple fields together.

    Allan

  • recibeTodorecibeTodo Posts: 7Questions: 2Answers: 1

    Thanks Kevin and Allan, maybe I can put an alert if I capture one of the two values that interest me, I'm trying to use to capture the values of the fields, but when this line is set,

    var rowData = table.row (this.parentNode) .data (); 
    
    

    Inline editing is deactivated. How can I capture one of these two values to send an alert?

    $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
            
            var rowData = table.row( this.parentNode ).data();
    
            if (rowData['dettagli.data_fattura'] > "0000:00:00"){
                editor.inline( this, {
                    buttons: { label: '&gt;', fn: function () { this.submit(); } }
                } );
            }
            
        });
    
This discussion has been closed.