Is there an on select autofill feature for Join tables?

Is there an on select autofill feature for Join tables?

bjshortybjshorty Posts: 20Questions: 6Answers: 0

Basically what i'm trying to do is have two tables Join. As I select a row id on a NEW form, the rest of the fields are filled with specific data from the Joined table.

Is there an example for this or an onSelect event?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,728Questions: 1Answers: 10,110 Site admin

    You can listen for the check event of the select input element using a standard jQuery listener - use field().input() to get the select element to which you would attach the event listener.

    Another option is to use the dependent() method.

    Regards,
    Allan

  • bjshortybjshorty Posts: 20Questions: 6Answers: 0

    With a simple Join, I was able to link the two tables.
    With this on 'change' event, I was able to get the employee_id on my volunteer.id textBox inside the form.

    editor.field( 'volunteer.name' ).input().on( 'change', function () {
                        editor.field( 'volunteer.id' ).val(editor.field( 'volunteer.name' ).val());
                        
                    });
    

    Now all I need is to get another value like the employee.office into a volunteer.office textBox when I change the same volunteer.name field.

    Field::inst( 'volunteer.name' )
                ->options('employees', 'employee_id', array('first_name', 'last_name'))
                ->validator( 'Validate::dbValues' ),
                    Field::inst( 'employees.first_name' ),
                    Field::inst( 'employees.last_name' ),
    
  • allanallan Posts: 61,728Questions: 1Answers: 10,110 Site admin
    Answer ✓

    Did you try either the dependent() method or using your own change event listener? They could make an Ajax request to get the options (or value if its only one value) for the child field.

    Allan

This discussion has been closed.