Dependent fields problem

Dependent fields problem

szakendreszakendre Posts: 24Questions: 10Answers: 0

Hi!
I use the following code, and it's working:

    editor1.dependent( 'option', function ( val )
    {
        return (val === 'value1' || val === 'value2') ?
            { show: ['field1', 'field2', 'field3'] }:
            { hide: ['field1', 'field2', 'field13'] };
    } );

Is it possible to change the simple if statement to real if - else if - else statement or switch statement?

I tied this, but doesn't work:

    editor1.dependent( 'option', function ( val )
    {
        if (val === 'value1' || val === 'value2')
        {
            show: ['field1', 'field2', 'field3'];
            return true;
        }
        else
        {
            hide: ['field1', 'field2', 'field3'];
            return false;
        }
    } );

I tried the following too, but doesn't work either:

    editor1.dependent( 'option', function ( val )
    {
        switch(val)
        {
            case 'value1':
                show: ['field1', 'field2', 'field3'];
                hide: ['field4', 'field5', 'field6'];
                return true;
            break;
            case 'value2':
                show: ['field4', 'field5', 'field6'];
                hide: ['field1', 'field2', 'field3'];
                return true;
            break;
        } 
    } );

What is the correct syntax of this expression?

Thank You and best regards.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    I haven't used dependent much but I think that you need to return the show/hide objects instead of true or false. Haven't tried it but I think this is what you want:

    editor1.dependent( 'option', function ( val )
    {
        if (val === 'value1' || val === 'value2')
        {
            return {show: ['field1', 'field2', 'field3']};
        }
        else
        {
            return {hide: ['field1', 'field2', 'field3']};
        }
    } );
    

    or

    editor1.dependent( 'option', function ( val )
    {
        switch(val)
        {
            case 'value1':
                return {show: ['field1', 'field2', 'field3'], hide: ['field4', 'field5', 'field6']};
            break;
            case 'value2':
                return {show: ['field4', 'field5', 'field6'],  hide: ['field1', 'field2', 'field3']};
            break;
        }
    } );
    

    Kevin

  • szakendreszakendre Posts: 24Questions: 10Answers: 0

    Dear Kevin,

    You are a real hero. :)

    Thank You.

This discussion has been closed.