Editor and left join doesn't works for me

Editor and left join doesn't works for me

ubicxubicx Posts: 3Questions: 1Answers: 0
edited June 2014 in Editor

hi

wen i add or update row i have this error from the server :
Fatal error: Call to a member function val() on a non-object in /var/www/vhosts/ubicx.com/httpdocs/admin/php/Editor/Editor.php on line 1017

I have made ​​a mistake?

javascript :

var editor = new jQuery.fn.dataTable.Editor( {
        "ajax": "php/table.TB_DOMAINES2.php",
        "table": "#TB_DOMAINES",
        "fields": [
                {
                    "label": "Nom",
                    "name": "TB_DOMAINES.C_LIBELLE",
                    "type": "text"
                },
                {
                    "label": "Date:",
                    "name": "TB_DOMAINES.D_DATEFIN",
                    "type": "date",
                    def:        function () { return new Date(); },
                    dateFormat: jQuery.datepicker.ISO_8601
                },
                {
                    "label": "Client:",
                    "name": "TB_SOCIETE.C_LIBELLE",
                    "type": "select"
                }
        ],
        i18n: {
            create: {
                button: "Nouveau",
                title:  "Créer nouvelle entrée",
                submit: "Créer"
            },
            edit: {
                button: "Modifier",
                title:  "Modifier entrée",
                submit: "Actualiser"
            },
            remove: {
                button: "Supprimer",
                title:  "Supprimer",
                submit: "Supprimer",
                confirm: {
                    _: "Etes-vous sûr de vouloir supprimer %d lignes?",
                    1: "Etes-vous sûr de vouloir supprimer 1 ligne?"
                }
            },
            error: {
                system: "Une erreur s'est produite, contacter l'administrateur système"
            }
        }   
} );


jQuery('#TB_DOMAINES').dataTable( {
        "sDom": "Tfrtip",
        "sAjaxSource": "php/table.TB_DOMAINES2.php",
        "oLanguage": {
            "sUrl": "http://ubicx.com/admin/fr.txt"
        },
        "aoColumns": [
            {
                    "mData": "TB_DOMAINES.C_LIBELLE"
            },
            {
                    "mData": "TB_DOMAINES.D_DATEFIN"
            },
            {
                    "mData": "TB_SOCIETE.C_LIBELLE"
            }
        ],
        "aaSorting": [[1,"asc"]],
        "oTableTools": {
                "sRowSelect": "single",
                "aButtons": [
                        { "sExtends": "editor_create", "editor": editor },
                        { "sExtends": "editor_edit",   "editor": editor },
                        { "sExtends": "editor_remove", "editor": editor }
                ]
        },
        initComplete: function ( settings, json ) 
        {
            editor.field('TB_SOCIETE.C_LIBELLE').update(json.TB_SOCIETE);
        }
} );

the php :

$out = Editor::inst( $db, 'TB_DOMAINES' )
    ->fields(
        Field::inst( 'TB_DOMAINES.C_LIBELLE' )
                    ->validator( 'Validate::notEmpty' ),
        Field::inst( 'TB_DOMAINES.D_DATEFIN' ),
                Field::inst( 'TB_SOCIETE.C_LIBELLE' )
    )     
        ->leftJoin( 'TB_SOCIETE', 'TB_SOCIETE.id', '=', 'TB_DOMAINES.ID_SOCIETE' )
        ->process($_POST)
        ->data();

if ( !isset($_POST['action']) ) 
{
    $out['TB_SOCIETE'] = $db
        ->selectDistinct( 'TB_SOCIETE', 'id as value, C_LIBELLE as label' )
        ->fetchAll();
}
echo json_encode( $out );

Answers

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

    Field::inst( 'TB_SOCIETE.C_LIBELLE' )

    Do you really want that, or do you want to alter the TB_DOMAINES.ID_SOCIETE field for the record? My guess is that you want to use TB_DOMAINES.ID_SOCIETE rather than trying to alter the joined table.

    Allan

  • ubicxubicx Posts: 3Questions: 1Answers: 0
    edited June 2014

    yes ! i want to alter the TB_DOMAINES.ID_SOCIETE with a select type (list of TB_SOCIETE)
    but i want to see TB_SOCIETE.C_LIBELLE in the datatable row

    ps : Sorry but I'm a french user and I may be missing something on the documentation

  • ubicxubicx Posts: 3Questions: 1Answers: 0

    ok I found !!
    i change

    "fields": [
    {
    "label": "Nom",
    "name": "TB_DOMAINES.C_LIBELLE",
    "type": "text"
    },
    {
    "label": "Date:",
    "name": "TB_DOMAINES.D_DATEFIN",
    "type": "date",
    def: function () { return new Date(); },
    dateFormat: jQuery.datepicker.ISO_8601
    },
    {
    "label": "Client:",
    "name": "TB_DOMAINES.ID_SOCIETE",
    "type": "select"
    }

            ],
    

    and
    initComplete: function ( settings, json )
    {
    editor.field('TB_DOMAINES.ID_SOCIETE').update(json.TB_SOCIETE);
    }

    and php
    ->fields(
    Field::inst( 'TB_DOMAINES.C_LIBELLE' )
    ->validator( 'Validate::notEmpty' ),
    Field::inst( 'TB_DOMAINES.D_DATEFIN' ),
    Field::inst( 'TB_SOCIETE.C_LIBELLE' ),
    Field::inst( 'TB_DOMAINES.ID_SOCIETE' )
    )

    thank you for help allan

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

    Hi,

    Great to hear you got it working! Thanks for posting your solution :-)

    Allan

This discussion has been closed.