Changing field type in editor depending on row dada

Changing field type in editor depending on row dada

AndreyAAndreyA Posts: 2Questions: 0Answers: 0

Hi! I'm currently trying to create a questionnaire in a form of a table with columns 'question','answer_type'(invisible column) ,'answer'. I would like to use Editor in inline mode for that task.

Is there any way to change type of the field 'answer' depending on value of field 'answer_type' (e.g. from select with yes/no options to textarea)?
Of course I understand that this will require some customisations from me, so i'm looking not for a ready-made solution but for a general directions.
Thanks in advance/

Replies

  • HPBHPB Posts: 73Questions: 2Answers: 18
    edited May 2017

    You will want to make use of clear() and add() right before you call editor.inline().

    Example code:

                $('#table').on('click', 'tbody td.editable', function () {
                    //Ignore click if already open
                    if(editor.display() == 'inline' && editor.displayed() == 'answer')
                        return;
    
                    editor.clear('answer');
                    var row = $(this).closest('tr');
                    var type = $('#table').DataTable().row(row).data()['answer_type'];
    
                    if(type == 'textarea')
                    {
                        editor.add( {
                            name: 'answer',
                            type: 'textarea'
                        } );
                    }
                    else if(type == 'select')
                    {
                        editor.add( {
                            name: 'answer',
                            type: 'select',
                            options: ['Yes', 'No']
                        } );
                    }
                    else
                    {
                        return;
                    }
                    editor.inline(this);
                });
    

    I hope this gets you in the right direction.

  • AndreyAAndreyA Posts: 2Questions: 0Answers: 0

    Thank you for the advise and example.

This discussion has been closed.