Help with dependant() method??

Help with dependant() method??

mornefinviewmornefinview Posts: 4Questions: 2Answers: 0
edited January 2020 in Free community support

how can I implement the dependant() method on a field of type date. In other words I want to change the data that is contained in a select according to the date i selected in the date field. this is all in editor.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    This is a simple example of dependent() when using dates - if the date is today, it changes the salary field. And this example shows how to modify selects - it adds it to the list if not already present.

    Colin

  • mornefinviewmornefinview Posts: 4Questions: 2Answers: 0
    edited January 2020

    Colin take your second example and change it so that if you choose a row and edit it and then on the edit form you change the date via the date picker as soon as the date picker closes after you have chosen a date the selector field should reload with new values in the select. this is what I am trying to accomplish so basically this is the code I have

    editortaskimport = new $.fn.dataTable.Editor( {
            ajax: {
                                    "url": "ajax_functions/update_tasks_import.php",
                                    "type": "POST",
                                    "data": function ( d ) {
    
                                            d.CompanyID = CompanyID;
                                            d.StateID = 1;
                                    },
                                    success: function(jsondata) {
                                        if(jsondata.length == 1 && jsondata[0]["Result"] == -1)
                                        {
    
                                            $('#task_management_import_table').DataTable().ajax.reload();
                                        }else{
                                            $('#task_management_import_table').DataTable().ajax.reload();
    
                                        }
                                    }
                                },
            table: "#task_management_import_table",
            fields: [
                    { label: "Subject",  name: "Subject" },
                    { label: "Details",  name: "Details",type: "textarea" },
                    { label: "Priority",  name: "Priority" ,type: "select" },
                    { label: "Tracking",  name: "Tracking" ,type: "select" },
                    { label: "DueDate",  name: "DueDate" ,type: "date",
                fieldInfo: "Enter the appointment date using the options above",
                def: function () {
                    return new Date();
                },
                        dateFormat: 'yy/mm/dd'},
                    { label: "RepeatType",  name: "RepeatType" ,type: "select" },
                    { label: "ImportClue",  name: "RepeatTypeComment" },
                    { label: "Every Number",  name: "EveryNumber" ,type: "select" },
                    { label: "Ends After # Repeats",  name: "EndsAfterRepeats" ,type: "select" },
                    { label: "WarningDays",  name: "WarningDays" ,type: "select" },
                    { label: "Contact",  name: "Contact" ,type: "select"},
                    { label: "Activity",  name: "Activity" ,type: "select"},
                    { label: "<?php echo str_replace("User",$content1,"User"); ?>",  name: "User",type: "select" }
            ],idSrc:  'ID'
        } );
    

    Below is test code this is where I have a problem if I type the date manually meaning with the keyboard and I click away from the field this code will run because the date field changed, BUT if i choose the date on the date picker that appears and the date changes this code doesn't run.

        editortaskimport.dependent( 'DueDate', function ( val ) {
        
                     return val == '2020/01/09' ?
    
                 { hide: ['Activity', 'Contact'] } :
                 { show: ['Activity', 'Contact'] };
         } );
    
  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    hide and show are used to remove fields, not values from selects. I've updated my example to put those two elements together - the select is being updated and a field is being hidden.

    Colin

This discussion has been closed.