create Button did nothing

create Button did nothing

Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

Link to test case:
If nessesary can send via pm
Debugger code (debug.datatables.net):
https://debug.datatables.net/ujebom
Error messages shown:
none
Description of problem:
this.submit() in the create window do nothing. The submit() in the edit and delete window works fine. I am a little bit confused, because the create did not rund the submit function and the others do that. The button config are the same.

Andreas

Here my JS Code:

var athForm;
var filter = {
    nat: '0',
    stat: '0',
    ag: '0'
};

$( document ).ready( function() {
    var dtButtons = [];
    athForm = new $.fn.dataTable.Editor( {
        table: '#athtbl',
        ajax: '/assets/php/Controller/athletes.php?ath=2',
        display: 'bootstrap',
        template: '#tplAthlete',
        fields: [
            {
                label: frmInfo.a_uuid + ':',
                name: 'a_uuid',
                data: 'DT_RowId',
                type: 'hidden'
            },{
                label: frmInfo.a_lastname + ': <span class="txt-Red">*</span>',
                name: 'a_lastname',
                data: 'lastname'
            },{
                label: frmInfo.a_firstname + ': <span class="txt-Red">*</span>',
                name: 'a_firstname',
                data: 'firstname'
            },{
                label: frmInfo.a_prefix + ':',
                name: 'a_prefix',
                data: 'prefix'
            },{
                label: frmInfo.a_gender + ': <span class="txt-Red">*</span>',
                name: 'a_gender',
                data: 'gender',
                type: 'select',
                options: [
                    { label: '', value: '' },
                    { label: 'Female', value: 'FEMALE' },
                    { label: 'Male', value: 'MALE' }
                ]
            },{
                label: frmInfo.a_birthdate + ': <span class="txt-Red">*</span>',
                name: 'a_birthdate',
                data: 'birthdate',
                type: 'datetime',
                opts: {
                    momentLocale: 'de-at',
                    minDate: new Date( '1950-01-01' ),
                    maxDate: new Date()
                },
                format: 'DD.MM.YYYY'
            },{
                label: frmInfo.a_nation + ': <span class="txt-Red">*</span>',
                name: 'a_nation',
                data: 'nation.iso3166_1_alpha3',
                type: 'select'
            },{
                label: frmInfo.a_club + ':',
                name: 'a_club',
                data: 'club.uuid',
                type: 'hidden'
            },{
                label: frmInfo.a_license + ': <span class="txt-Red">*</span>',
                name: 'a_license',
                data: 'license'
            },{
                label: frmInfo.a_ranking + ':',
                name: 'a_ranking',
                data: 'rankingid'
            },{
                label: frmInfo.a_owner + ':',
                name: 'a_owner',
                data: 'owner.uuid',
                type: 'select'
            },{
                label: frmInfo.a_status + ':',
                name: 'a_status',
                data: 'status',
                type: 'select',
                options: [
                    { label: 'Active', value: 'ACTIVE' },
                    { label: 'Inactive', value: 'INACTIVE' },
                    { label: 'Imported', value: 'IMPORT' }
                ],
                def: 'ACTIVE'
            },{
                label: frmInfo.a_type + ':',
                name: 'a_type',
                data: 'type',
                type: 'select',
                options: [
                    { label: 'Athlete', value: 'CHILD' },
                    { label: 'Athlete Child', value: 'ATHLETE' }
                ],
                def: 'CHILD'
            }
        ]
    } );

  dtButtons.push( {
        extend: 'create',
        editor: athForm,
        text: '<i class="fas fa-user-plus txt-DodgerBlue"></i>',
        className: 'bg-White',
        titleAttr: btnInfo.a_create,
        formButtons: [
            { text: btnInfo.a_add, action: function() { this.submit(
                function( dt ) {
          pushNotify( 'success', frmMsg.create_title, frmMsg.create_text, true );
                },
                function( dt ) {
          if( true == debug ) {
                      pushNotify( dt.errInfo.type, dt.errInfo.status + ' ' + dt.errInfo.title, dt.errInfo.text );
          }
                }
            ); }, className: 'btn-DodgerBlue' },
            { text: btnInfo.a_cancel, action: function() { this.close(); }, className: 'btn-WhiteSmoke ml-10' }
        ],
        formTitle: '<i class="fas fa-user-plus txt-DodgerBlue bold"></i> <span class="txt-DodgerBlue bold">' + btnInfo.a_create + '</span>'
    } );

    dtButtons.push( {
        extend: 'editSingle',
        editor: athForm,
        text: '<i class="fas fa-user-edit txt-DarkGreen"></i>',
        className: 'bg-White',
        titleAttr: btnInfo.a_edit,
        formButtons: [
            { text: btnInfo.a_save, action: function() { this.submit(
                function( dt ) {
                    var type = dt.data.type
                    if( 'error' == type ) {
                        _PNotify( type, dt.data.errCode + ' ' + dt.data.errShort, dt.data.icon, dt.data.info );
                    } else {
                        _PNotify( type, frmMsg.edit_title, 'far fa-check-square fs-18', frmMsg.edit_text );
                    }
                },
                function( dt ) {
                    _PNotify( type, dt.data.errCode + ' ' + dt.data.errShort, dt.data.icon, dt.data.info );
                }
            ); }, className: 'btn-DarkGreen' },
            { text: btnInfo.a_cancel, action: function() { this.close(); }, className: 'btn-WhiteSmoke ml-10' }
        ],
        formTitle: '<i class="fas fa-user-edit txt-DarkGreen bold"></i> <span class="txt-DarkGreen bold">' + btnInfo.a_edit + '</span>'
    } );
.....
    var alist = $( '#athtbl' ).DataTable( {
        language: {
            url: i18n_url
        },
        ajax: {
            url: ajaxurl + '&cu=' + c_uuid + '&st=0&na=0&ag=0',
            type: 'POST',
            dataSrc: 'content'
        },
        autoWidth: false,
        select: 'multi',
        serverSide: true,
        processing: true,
        order: [ [ 1, 'asc' ] ],
        lengthMenu: [ [ 15, 25, 50, 100, -1 ], [ 15, 25, 50, 100, 'All' ] ],
        pagingType: 'numbers',
        dom: "<'row'<'col-sm-4'l><'col-sm-4 DT_Buttons_Style'B><'col-sm-4'f>>rt<'row'<'col-sm-6'i><'col-sm-6'p>>",
        columnDefs: [
            { targets: 0, visible: true, width: '1.5%' },
            { targets: 1, visible: true, searchable: true, orderable: true },
            { targets: 2, visible: true, width: '3%', className: 'text-center' },
            { targets: 3, visible: true, width: '4%', className: 'text-center' },
            { targets: 4, visible: true, width: '5%', className: 'text-center' },
            { targets: 5, visible: true, width: '5%', className: 'text-center' },
            { targets: 6, visible: true, className: 'text-left' },
            { targets: 7, visible: true, width: '7%', className: 'text-center' },
            { targets: '_all', visible: false, searchable: false, orderable: false }
        ],
        columns: [
    .....
        ],
        buttons: dtButtons,
        initComplete: function () {
            $( '#athtbl' ).removeClass( 'hidden' );
        }
    } );

    athForm.on( 'open preSubmit', function( e, o, action ) {
        if( 'create' == action ) {
            $( 'div.modal-dialog' ).removeClass().addClass( 'modal-dialog create-dialog' );
            $( 'div.modal-content' ).removeClass().addClass( 'modal-content action_create' );
        } else if( 'edit' === action ) {
            $( 'div.modal-dialog' ).removeClass().addClass( 'modal-dialog edit-dialog' );
            $( 'div.modal-content' ).removeClass().addClass( 'modal-content action_edit' );
        } else if( 'remove' === action ){
            $( 'div.modal-dialog' ).removeClass().addClass( 'modal-dialog' );
            $( 'div.modal-content' ).removeClass().addClass( 'modal-content action_remove' );
        }

        if( 'remove' !== action && 'preSubmit' === e.type ) {
            var firstName = this.field( 'a_firstname' );
            if ( ! firstName.val() ) {
                firstName.error( frmError.a_firstname );
            } else if ( firstName.val().length <= 2 ) {
                firstName.error( frmError.a_firstname_min );
            }
            var lastName = this.field( 'a_lastname' );
            if ( ! lastName.val() ) {
                lastName.error( frmError.a_lastname );
            } else if ( lastName.val().length < 2 ) {
                lastName.error( frmError.a_lastname_min );
            }
            var birth = this.field( 'a_birthdate' );
            if ( ! birth.val() ) {
                birth.error( frmError.a_birthdate );
            }
            var nation = this.field( 'a_nation' );
            if ( ! nation.val() ) {
                nation.error( frmError.a_nation );
            }
            var club = this.field( 'a_club' );
            if ( ! club.val() ) {
                club.error( frmError.a_club );
            }
            var gender = this.field( 'a_gender' );
            if ( ! gender.val() ) {
                gender.error( frmError.a_gender );
            }
      var license = this.field( 'a_license' );
      if( ! license.val() ) {
        license.error( frmError.a_license );
      }
            if ( this.inError() ) {
                return false;
            }
        }
    } );
} );

Answers

  • allanallan Posts: 61,683Questions: 1Answers: 10,099 Site admin

    If nessesary can send via pm

    Yes please :). The error you are seeing, assuming the Ajax request is going out when the save button is pressed, means the server isn't returning the JSON data that Editor expects.

    If the Ajax request is not going out, then the preSubmti event handler must be cancelling the submit for some reason.

    Regards,
    Allan

Sign In or Register to comment.