Change value of another cell based on one cell input

Change value of another cell based on one cell input

aungkoheinaungkohein Posts: 38Questions: 5Answers: 0

Hi!

Suppose I input a value in column 1, I want to auto change the value of another cell in column 2 (same row), what is the syntax I should use in "????" ?

table.abc.js:

$( editor.field( 'columnA' ).input() ).on( 'keyup', function (e, d) {
if ( ! d || ! d.editor ) {

    if ( ???? ) {
            editor.field( 'status' ).val( "Open");
    }else {
            editor.field( 'status' ).val( "Closed");  
    }

}

Please help!

Replies

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @aungkohein ,

    You could use dependent() for that,

    Cheers,

    Colin

  • aungkoheinaungkohein Posts: 38Questions: 5Answers: 0
    edited January 2019

    Hi @colin!

    Thank you for the help. I read the dependent() api but only managed to understand the show/hide on popup form. I hope there is more full examples with to it.

    I chanced upon this which solved the issue: https://editor.datatables.net/reference/api/field().input()

    Code:
        $( editor.field( 'job' ).input() ).on( 'keyup', function (e, d) {
        if ( ! d || ! d.editor ) {
    
            if ( editor.field( 'job' ).val() === 'done' ) {
                editor.field( 'status' ).val( "Re-open");
            }
        }
        } );
    

    cheers!

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @aungkohein ,

    This here may help - it shows dependent() being used as I mentioned before. What you have though is good, so no point changing! :)

    Cheers,

    Colin

  • aungkoheinaungkohein Posts: 38Questions: 5Answers: 0

    Hi @colin,

    Great example. Will implement it also in other parts. Thanks! =DD

  • aungkoheinaungkohein Posts: 38Questions: 5Answers: 0
    edited January 2019

    Hi @colin,

    I tested the earlier code. It only work if keyboard is used to select the dropdown value (autocomplete). If I use mouse to select the value from the autocomplete dropdown, the change event did not fire.

    I tried all the $( editor.field( 'job' ).input() ).on( 'xxxx', ...), but does not work.

    What syntax should I use?

    I tried adding dependent() but there is no effect:

    editor.dependent('job', function(val, data, callback) {
    if (val === 'done') {
      editor.field('status').set('Re-open');
    }
    callback(true);
    

    })

  • aungkoheinaungkohein Posts: 38Questions: 5Answers: 0

    Dependent() does work because I'm using Inline Editor. How can I use dependent() and submit on keyup?

  • allanallan Posts: 61,436Questions: 1Answers: 10,049 Site admin

    If I use mouse to select the value from the autocomplete dropdown, the change event did not fire.

    What auto complete library are you using? Can you give me a link to your page so I can take a look?

    Allan

This discussion has been closed.