Dependant question

Dependant question

ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
edited October 2023 in General

Hi, i m trying to build a table where the user write a date on CELL1 and it complete CELL2 :

//DEPENDANT
editor.dependent('CELL1', function(val, data, callback) {
if (val != null) {
console.log('oui'),
editor.field('CELL2').set('0');
}
callback(true);
});

the code above work perfeclty, but i want to add the condition that if the CELL 2 isn't emty, it doesn't set the value to 0. How to do that ? Because the variable val is for CELL1 only. I have tried with differents things like the variable full that i use in render fonction to get value from others cells but nothing work, can you help me pls ?

thx in advance for you time :)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    if (editor.field('CELL2').val() === '') {
      editor.field('CELL2').set('0');
    }
    

    Should do it.

    Allan

  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
    edited October 2023

    Thank for your answer but now i have another problem :

    Cell 1 is a date
    Cell 2 is a dropdown with 3 value possible null, 0 (render as 'non') and 1 (render as 'oui')

    here is the code on my condition on dependent:

    editor.dependent('CELL1', function(val, data, callback) {
            if (val == '') {
                editor.field('CELL2').set(null);
            } else if (val != '' && editor.field('CELL2').val() == '') {
                editor.field('CELL2').set('0');
            }
            callback(true);
    
        });
    

    Case 1 (work as intended) : User enter a date in cell1, cell 2 is autocomplete with value = 0 (render as 'non')

    Case 2 (work as inteded) : User modify the date in cell1, cell 2 value doesn't change

    Case 3 (work as inteded) : User delete the date in cell1, cell 2 value is also deleted

    Case 4 (doesn't work as inteded) : Cell1 is empty, cell2 have a value (0 or 1 render as 'non' or 'oui') -> when i click on the cell to modify the value with inline-editing, the defaut selected value is null and not the value of the cell.

    Illustration case 4 :
    (Before click)

    (when i click on the cell) :

    (when i click again on the dropdown) :

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Can you show me the configuration for that field, and the data which is being loaded into the DataTable please?

    Thanks,
    Allan

  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
    edited October 2023

    here is the config for cell2 :

    { data: 'DATA.SUIVIJURIDIQUE_2021.RETOURCLI_SM2', name:"RETOURCLI_SM2", type: "ouinon", className: 'dt-center editable-juridique-2021', searchBuilderTitle: '[RETOUR CLIENT] Oui / Non', width: "70px",
                render: function (data, type){
                    if (type === 'display'){
                        if (data == "") return "";
                        if (data == "1") return "Oui";
                        if (data == "0") return "Non";
                    }
                return data;
                },
            },
    

    the data in the database is null or 0 or 1 depending on the selected value.

    The type is 'ouinon' because i have setup a special filter with searchbuilder that show only the option that i want (because i user server side and it can't show only the options availables in my database), but that have no importance because if i disable the type it's still work the same.

    For the case 4, i think when i click on the cell to modify the value with inline-editing, it already go in my dependant condition (see bellow) and that's why the default value in the inline-editing field is null and not the true value of the cell. If i don't modify the value (i have a confirm button on inline-edditing) and exit the field, the true value still there (before click image see above)

    editor.dependent('CELL1', function(val, data, callback) {
            if (val == '') {
                editor.field('CELL2').set(null); // IT GO THERE
            } else if (val != '' && editor.field('CELL2').val() == '') {
                editor.field('CELL2').set('0');
            }
            callback(true);
        });
    
  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1

    Do you have a solution ?

    After some testing i m sure it's because when i click on the cell with inline-editing, it already go in the first if condition on my dependent and that's why value select in the dropdown is null and not the true value of the cell...

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Apologies, I missed your previous reply. That's the column definition - can you show me the field definition as well please? I'd like to also see the JSON data being used to populate the table (assuming that you are using Ajax). Even better would be if you could link to a page showing the problem.

    Thanks,
    Allan

  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
    edited October 2023

    is it possible to create a test case with editor ? I can reproduce it if it's possible to have a test case with editor. I think it's gonna be easier for you and i.

    Because i use serverside so the json data is directly from my database (which i can't share you the data...). Here is the field definition in staff.php

    // RETOUR CLIENT
            Field::inst( 'DATA.SUIVIJURIDIQUE_2021.RETOURCLI_SM2' )             // Retour client 
                ->setFormatter( Format::ifEmpty( null ) ),
    
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    You can, however, it won't be using your PHP, unless you can just link to your page.

    If you can show me the Javascript field definition and the JSON return, that would be useful.

    Perhaps also try the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Allan

Sign In or Register to comment.