Field validation vs. Deletion

Field validation vs. Deletion

Arthur_KozinskiArthur_Kozinski Posts: 8Questions: 3Answers: 0

Hello there,

I just started using Editor , and I'm struggling with the field validation when deleting a row.

I.c.:

  • I added a field validation for a date field which is required when inserting new records

        ->validator( 'Validate::required', array(
            "message" => "Gelieve een begindatum op te geven"
        ) )
    
  • Nonetheless, my table contains certain records which are missing this field (old dirty data). When trying to remove these records through the datatables/editor, the delete fails (fieldErrors:[{name: "calendar_vrijstelling.dtm_vanaf", status: "Gelieve een begindatum op te geven"}]).

Question: Is it possible to circumvent/bypass field validation when deleting? Or is this not possible and should i start working with preSubmit validation?

Thnx alot for any advice,

Arthur

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    The individual field validation shouldn't run when deleting a row. I've just tried it locally and wasn't able to make that error happen.

    Could you show me your full PHP file for the Editor configuration and also let me know what version of the PHP libraries you are using please?

    Allan

  • Arthur_KozinskiArthur_Kozinski Posts: 8Questions: 3Answers: 0
    edited January 2018

    Hi Allan,

    thnx for the prompt reply.

    Here you can see the php file for the editor (not the javascript/jquery stuff)

    I'm using version @version 1.6.3 (tried to upgrade to 1.7.0 but received a bunch of errors concerning passwords and stuff, but don't have enough time for the moment to do the upgrade)

    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\ExtOptions,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'calendar_vrijstelling' )
        ->fields(
            Field::inst( 'calendar_vrijstelling.artsid' )
                ->options( ExtOptions::inst()
                    ->pre(array(array("value"=>"","label"=>"Selecteer een arts")))
                    ->table( 'hvg_signup' )
                    ->value( 'masterID' )
                    ->label( array('name', 'voornaam') )
                    ->where( function ($q) {
                        $q->where( 'verwijderd', '0', '=' );
                        }
                    )
                    ->order( 'name asc, voornaam asc' )
                    ->render( function ( $row ) {
                        return $row['name'].', '.$row['voornaam'];
                }) 
            )
                ->validator( 'Validate::dbValues' , array(
                    "message" => "Gelieve een arts te selecteren..."
                ) ),
            Field::inst( 'hvg_signup.wachtpost_alias' ),
            Field::inst( 'hvg_signup.subkring' ),
            
            Field::inst( 'calendar_vrijstelling.categorie' )
                ->options( ExtOptions::inst()
                    ->pre(array(array("value"=>"","label"=>"Selecteer een categorie")))
                    ->table( 'calendar_vrijstelling_categorie' )
                    ->value( 'calendar_vrijstelling_categorie.external_id' )
                    ->label( 'calendar_vrijstelling_categorie.naam' )
                )
                ->validator( 'Validate::dbValues' , array(
                    "message" => "Gelieve een categorie te selecteren..."
                ) ),
            Field::inst( 'calendar_vrijstelling_categorie.naam' ),
            
            Field::inst( 'calendar_vrijstelling.dtm_vanaf' )
                ->validator( 'Validate::dateFormat', array(
                    "format"  => Format::DATE_ISO_8601,
                    "message" => "Gelieve het volgende formaat te gebruiken: JJJJ-mm-dd"
                ) )
                ->validator( 'Validate::required', array(
                    "message" => "Gelieve een begindatum op te geven"
                ) )
                ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
                ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ) ,
                        
                
            Field::inst( 'calendar_vrijstelling.dtm_tot' )
                ->validator( 'Validate::dateFormat', array(
                    "format"  => Format::DATE_ISO_8601,
                    "message" => "Gelieve het volgende formaat te gebruiken:  JJJJ-mm-dd"
                ) )
                ->validator( 'Validate::required', array(
                    "message" => "Gelieve een einddatum op te geven"
                ) )
                ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
                ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),
            
            Field::inst( 'calendar_vrijstelling.opmerking' ),
            Field::inst( 'calendar_vrijstelling.tsupdate' ),
            Field::inst( 'calendar_vrijstelling.verwijderd' ),
            Field::inst( 'calendar_vrijstelling.put_offline' )
    
        )
    
        ->leftJoin('hvg_signup','hvg_signup.masterID','=', 'calendar_vrijstelling.artsid')
        ->leftJoin('calendar_vrijstelling_categorie','calendar_vrijstelling_categorie.external_id','=', 'calendar_vrijstelling.categorie')
        ->where( 'calendar_vrijstelling.verwijderd', 0 )
        ->process( $_POST )
        ->json();
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I've just had a look at the source for 1.6.3 and at the top of the validate function it has:

            if ( $data['action'] != "create" && $data['action'] != "edit" ) {
                return true;
            }
    

    Could you show me the data that is being submitted to the server when to trigger the delete action please? If you have a link to the page in question that would be even better.

    Thanks,
    Allan

This discussion has been closed.