PHP Datatable\Editor doesn't give a value

PHP Datatable\Editor doesn't give a value

microshopmicroshop Posts: 11Questions: 4Answers: 1

When using Editor, the user edit a row. I want to know some field values submitted by the user, in server side.

In PHP, I use this method:

->on('preEdit', function ( $editor, $values ) {
        $val = $editor->field('myField')->getValue();
    })

$val returns empty.

And $editor->field('myField') returns this:

DataTables\Editor\Field Object
(
    [_dbField:DataTables\Editor\Field:private] => myField
    [_get:DataTables\Editor\Field:private] => 1
    [_getFormatter:DataTables\Editor\Field:private] => 
    [_getFormatterOpts:DataTables\Editor\Field:private] => 
    [_getValue:DataTables\Editor\Field:private] => 
    [_opts:DataTables\Editor\Field:private] => 
    [_optsFn:DataTables\Editor\Field:private] => 
    [_name:DataTables\Editor\Field:private] => myField
    [_set:DataTables\Editor\Field:private] => both
    [_setFormatter:DataTables\Editor\Field:private] => 
    [_setFormatterOpts:DataTables\Editor\Field:private] => 
    [_setValue:DataTables\Editor\Field:private] => 
    [_validator:DataTables\Editor\Field:private] => Array
        (
        )

    [_upload:DataTables\Editor\Field:private] => 
    [_xss:DataTables\Editor\Field:private] => 
    [_xssFormat:DataTables\Editor\Field:private] => 1
)

So, I don't know how to know the value of a field submitted by the user in the editor.

This question has an accepted answers - jump to answer

Answers

  • microshopmicroshop Posts: 11Questions: 4Answers: 1
    edited January 2018 Answer ✓

    I solved this.

    First, this is bad:

    ->on('preEdit', function ( $editor, $values ) {
            $val = $editor->field('myField')->getValue();
        })
    

    The function accepts ($editor, $id, $values), not ($editor, $values). (...I copied the function from preCreate).

    And then, with $values, I've accesed to the array and I've get the values that needed.

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Thanks for posting back - great to hear you've got it working.

    Allan

This discussion has been closed.