Select fields autopopulate on adding new record

Select fields autopopulate on adding new record

helpdeskhelpdesk Posts: 20Questions: 3Answers: 0

Hi,
is there a possibility to auto populate select inputs depending on previous choice from database on the new/edit record?

Like ajax request on change :)

Thanks,
Jakub

Replies

  • allanallan Posts: 61,822Questions: 1Answers: 10,129 Site admin

    Have a look at the dependent() code which I think will do what you are looking for (you have two selects and the values shown in the second should be dependent upon the first?).

    Allan

  • helpdeskhelpdesk Posts: 20Questions: 3Answers: 0
    edited September 2015

    Yes,
    that is what I'll need, but still cant figure it out. Do you have any examples? This will simplify a lot for me :)

    I know how to target an element which will call function like here:

    editor.dependent( 'options', function ( val ) {
    return val === 'Simple' ?
    { hide: ['position', 'office', 'extn', 'start_date', 'salary'] } :
    { show: ['position', 'office', 'extn', 'start_date', 'salary'] };
    } );

    But I'm confused how to address the new select field and update it's select options, and how should it be formatted.

    Thanks,
    Jakub

  • helpdeskhelpdesk Posts: 20Questions: 3Answers: 0

    editor.dependent('area', function (val, data, callback) {

                    $.ajax({
                        url: '123.php',
                        data: {
                            id: editor.val('area')
                        },
                        type: 'post',
                        dataType: 'json',
                        success: function (res) {
    
                            editor.field('farm').update( res );
                        }
                    });
                });
    

    This one worked for me, thanks

    Data structure:

    {

    "name1": "val1",
    "name2": "val2"
    

    }

  • allanallan Posts: 61,822Questions: 1Answers: 10,129 Site admin

    Hi,

    Good to hear you got it working :-)

    Regards,
    Allan

This discussion has been closed.