Standalone Editor Not Updating

Standalone Editor Not Updating

webvisionwebvision Posts: 10Questions: 7Answers: 0
edited October 2014 in Free community support

I'm implementing a standalone editor and it's not updating. Can anyone see the problem?

Javascript:

var Heditor; 
$(document).ready(function() {
    Heditor = new $.fn.dataTable.Editor( {
        ajax: "/report_modules/pf2/act/PF2_Head_Standalone.php?fid=1",
        fields: [ {
                label: "Invoice #:",
                name:  "f_invoice_number"
            }, {
                label: "Invoice Date:",
                name:  "f_date",
                type: "date",
                dateFormat: "yy-mm-dd"
            }, {
                label: "Location:",
                name:  "f_location"
            }, {
                label: "County:",
                name:  "f_county"
            }, {
                label: "State:",
                name:  "f_state"
            }, {
                label: "P.O. Number:",
                name:  "f_po_number"
            }, {
                label: "Operator",
                name: "f_operator"
            }, {
                label: "Contract/Rig",
                name: "f_contract_rig"
            }, {
                label: "Authorized By",
                name: "f_authorized_by"
            }
        ]
    } ); 
    /*$('#edit').on( 'click', function () {
        Heditor
            .buttons( {
                label: "Save",
                fn: function () { this.submit(); }
            } )
            .edit(1);
    } );*/
    $('[data-editor-field]').on( 'click', function (e) {
        Heditor.inline( this, {
            buttons: '_basic'
        } );
    } );
} );

HTML:

<dl>
    <dt>Invoice #:</dt>
    <dd data-editor-field="f_invoice_number">12345</dd>

    <dt>Date:</dt>
    <dd><span data-editor-field="f_date">2014-09-09</span></dd>
    
    <dt>P.O. Number:</dt>
    <dd data-editor-field="f_po_number">54321</dd>
    
    <dt>County:</dt>
    <dd data-editor-field="f_county"></dd>
    
    <dt>State:</dt>
    <dd data-editor-field="f_state"></dd>
    
    <dt>Location:</dt>
    <dd data-editor-field="f_location"></dd>
    
    <dt>Contract/Rig:</dt>
    <dd data-editor-field="f_contract_rig"></dd>
    
    <dt>Authorized By:</dt>
    <dd data-editor-field="f_authorized_by"></dd>
    
    <dd><button id="edit">Edit</button></dd>
</dl>

Server Side:

if ( isset($_POST['action']) && ( $_POST['action'] === 'create' || $_POST['action'] === 'edit' ) ) {
   $_POST['data']['f_id'] = htmlspecialchars($_GET["fid"]);
}

Editor::inst( $db, 'tblPF2_Head' )
    ->fields(
        Field::inst( 'id' )->set( false ),
        Field::inst( 'f_po_number' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'f_operator' ),
        Field::inst( 'f_contract_rig' ),
        Field::inst( 'f_authorized_by' ),
        Field::inst( 'f_location' ),
        Field::inst( 'f_county' ),
        Field::inst( 'f_state' ),
        Field::inst( 'f_date' ) 
            ->validator( 'Validate::dateFormat', array(
                "format"  => Format::DATE_ISO_8601,
                "message" => "Please enter a date in the format yyyy-mm-dd"
            ) )
            ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
            ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 )
    )->where( $key = "id", $value = htmlspecialchars($_GET["fid"]), $op = '=' )
    ->process( $_POST )
    ->json();

Answers

  • webvisionwebvision Posts: 10Questions: 7Answers: 0

    I was able to get the basic edit button working. Unfortunately, I'm not able to get inline working. How do I pass the ID for the inline editing to work?

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Hi,

    I'm afraid you've come across one of the "clunky" parts of Editor here... The chunkiness will be resolved in a future update - but for the moment what you need to do is use the preSubmit event to attach the id.

    For example you might have:

    editor.on( 'preSubmit', function ( e, data ) {
      data.id = 'myId';
    } );
    

    The reason for this is that the first parameter for inline() is the identifier for which field to edit. In DataTables it is possible to get the id from that node, but that isn't the case in standalone mode.

    To resolve this there are three options I can think of:

    1. Require that an id be specified somewhere in the HTML that is defined in the Editor spec
    2. An API method to set the ID (would be for standalone mode only)
    3. An init option to set the ID (would be for standalone mode only)

    Would be interested in your thoughts.

    Allan

This discussion has been closed.