Editor not populating fields in Update mode

Editor not populating fields in Update mode

peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0

Creating new record works fine. However when updating a record, not all fields are displayed.

The Unit select list needs to be populated with the selected option shown as per the database record.

And then the Learning Events populated and selected also.

Same with the Unit Outcomes field.

One problem is that the last two fields are dependant on the Unit select list when creating a new record.

Which confuses the issue as to how to do the Update fields.

Answers

  • peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0

    var editor = new $.fn.dataTable.Editor( { ajax: "program_data/learning_event_outcome_data.php", table: "#learning_event_outcome_table", template: '#learning_event_outcome_form', fields: [ { label: "Learning Event Outcome:", name: "learning_event_outcome.learning_event_outcome", type: "ckeditor" }, { label: "Unit:", name: "unit.unit_pk", type: "select", placeholder: "Select a Unit..." }, { label: "Learning Events:", name: "learning_event[].learning_event_pk", type: "select", placeholder: 'No selection', placeholderDisabled: false, placeholderValue: 0, multiple: true }, { label: "Unit Outcomes:", name: "unit_outcome[].unit_outcome_pk", type: "select", placeholder: 'No selection', placeholderDisabled: false, placeholderValue: 0, multiple: true }] } ); var units = []; $.getJSON("program_data/get_units.php", function(data) { var option = {}; $.each(data, function(i,e) { option.label = e.text; option.value = e.id; units.push(option); option = {}; }); }).done(function(){editor.field('unit.unit_pk').update(units); }); editor.dependent('unit.unit_pk', 'program_data/get_le.php'); editor.dependent('unit.unit_pk', 'program_data/get_unit_outcomes_les.php'); var table = $( '#learning_event_outcome_table' ).DataTable( { responsive: true, "autoWidth": false, ajax: "program_data/learning_event_outcome_data.php", dom: "Blfrtip", columns: [ { data: "learning_event_outcome.learning_event_outcome", width: '50%' }, { data: "learning_event", render: "[, ].learning_event_name" }, { data: "unit_outcome", render: "[, ].unit_outcome" }, { data: "learning_event_outcome.modified" }, { data: "learning_event_outcome.modified_by" }], select: { style: 'os', selector: 'td:first-child' }, buttons: []
  • peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
    
    Editor::inst( $db_cm_dopt, 'learning_event_outcome', 'learning_event_outcome_pk' )    
        ->field(
            Field::inst( 'learning_event_outcome.learning_event_outcome' ),
            Field::inst( 'learning_event_outcome.modified' ),
            Field::inst( 'learning_event_outcome.modified_by' )->setValue( $user )
        )
         ->join(
            Mjoin::inst( 'learning_event' )
                ->link( 'learning_event_outcome.learning_event_outcome_pk', 'learning_event_learning_event_outcome_lookup.learning_event_outcome_fk' )
                ->link( 'learning_event.learning_event_pk', 'learning_event_learning_event_outcome_lookup.learning_event_fk' )
                ->order( 'learning_event.learning_event_name asc' )
                ->fields(
                    Field::inst( 'learning_event_pk' )
                        ->options( Options::inst()
                            ->table( 'learning_event' )
                            ->value( 'learning_event_pk' )
                            ->label( 'learning_event_name' )                  
                        ),
                    Field::inst( 'learning_event_name' )
                )
        )
         ->join(
            Mjoin::inst( 'unit_outcome' )
                ->link( 'learning_event_outcome.learning_event_outcome_pk', 'unit_outcome_learning_event_outcome_lookup.learning_event_outcome_fk' )
                ->link( 'unit_outcome.unit_outcome_pk', 'unit_outcome_learning_event_outcome_lookup.unit_outcome_fk' )
                ->order( 'unit_outcome.unit_outcome asc' )
                ->fields(
                    Field::inst( 'unit_outcome_pk' )
                        ->options( Options::inst()
                            ->table( 'unit_outcome' )
                            ->value( 'unit_outcome_pk' )
                            ->label( 'unit_outcome' )
                            ->render( function ( $row ) {
                return strip_tags($row['unit_outcome']);
            } )
                            ->order( 'unit_outcome' )
                        ),
                    Field::inst( 'unit_outcome' )
                )
        )
        ->process($_POST)
        ->json();
    
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Are you able to give me a link to the page so I can take a look at it? I'll need to be able to see the data that is populating the DataTable. You can PM me by clicking my forum user name and then "Send message".

    Thanks,
    Allan

Sign In or Register to comment.