1st: SET_EDIT and SET_CREATE on same FIELD // 2nd A system error has occurred

1st: SET_EDIT and SET_CREATE on same FIELD // 2nd A system error has occurred

Caspian deConwyCaspian deConwy Posts: 15Questions: 2Answers: 0
edited October 2019 in Free community support

Hi,

I want to have two events for preEdit and preCreate on one and the same field.
Is this possible - something like following:

        Field::inst( 'artnum' )->set( Field::SET_CREATE )>set( Field::SET_EDIT ), ???

Another question is about an error I receive by creating a new row. Even though the row is correctly inserted in the database, the error appears and the editor popup does not close. But in the console/nwetwork tab I do not get any error.

    ->on( 'preCreate', function ( $editor, $values ) {
        $marke  = $values['marke'];
        print "Marke: " . $marke . "<br/>\n";
        $new_artnum = "LNC" . strtoupper(substr($marke, 0, 3));
        print "New_Artnum: " . $new_artnum . "<br/>\n";
        $result = $editor->db()->raw()
            ->exec( "SELECT MAX(artnum) AS max_artnum FROM preisliste_intern WHERE artnum LIKE '$new_artnum%'" );
        $row = $result->fetch(PDO::FETCH_ASSOC);
        $max_artnum = $row['max_artnum'];
        print "Max_Artnum: " . $max_artnum . "<br/>\n";
        if(strlen($max_artnum) == 12) {
          print 1;
          $nummer = substr($max_artnum, 6, 6) + 1;
          $new_artnum = $new_artnum . $nummer;
        } else {
          print 2;
          $new_artnum = $new_artnum . "100001";
        }

        $editor
          ->field( 'artnum' )->setValue( $new_artnum );
        $editor
          ->field( 'erstellt' )->setValue( time() );
        $editor
          ->field( 'archiv' )->setValue( "0" );
    } )

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    Answer ✓

    Hi @Caspian deConwy ,

    I want to have two events for preEdit and preCreate on one and the same field.

    You would use "SET_BOTH", see here.

    Another question is about an error I receive by creating a new row.

    Could you say what the error is, please?

    Cheers,

    Colin

  • Caspian deConwyCaspian deConwy Posts: 15Questions: 2Answers: 0
    edited October 2019

    Thank you, Colin.

    SET_BOTH does it.

    About the error, sorry, it was: "A system error has occured". But I think it's gone and was due to the not properly set up SET_EDIT/_CREATE condition. The submitError function only lead me to somewhere in the js-file so I could not figure out what the issue was.

This discussion has been closed.