validator blocks update

validator blocks update

MadMax76MadMax76 Posts: 142Questions: 31Answers: 1

Hi,

I am having this update-function for rows:

$('#liste_freigaben').on('change', 'input.editor-active', function () {
            let now = new Date().toISOString().split('Z');
            editor_freigaben
                    .edit($(this).closest('tr'), false)
                    .set({
                        'V_Freigaben.freig_erledigt': $(this).prop('checked') ? 1 : 0,
                        'V_Freigaben.freig_erledigt_durch': __thisPID__,
                        'V_Freigaben.freig_erledigt_wann': now.length ? now[0] : '' }
                    )
                .submit();

this does work, but when this validator is active:

        Field::inst( 'V_Freigaben.freig_person' )
            ->options( Options::inst()
                ->table( 'V_NeueFreigeber' )
                ->value( 'PID' )
                ->label( 'NamePers' )
                ->where( function ( $q ) use ( $selectedStapelname, $selectedINP_ID  ) {
                        $q->where( 'Stapelname', $selectedStapelname )
                            ->and_where( function ( $r )  use ( $selectedINP_ID ) {
                                $r->where( 'INP_ID', $selectedINP_ID );});
                            } )
                     )
            ->validator( Validate::minNum(    //this causing the problem!!!!
                1,
                '.',
                ValidateOptions::inst()
                    ->message( 'Freigeber muss ausgewählt werden' )
                    ->allowEmpty( false )
                    ->optional( false )
            ) ),

it is blocked with the error shon in the message-box. As he is picking a already existing line, there must be a "freig_person", therefore the validator should not be a problem?

Thanks
Max

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 57,737Questions: 1Answers: 9,204 Site admin
    Answer ✓

    Hi Max,

    Can you show me the request data that is being sent to the server please? You can find that in the network inspector's "Headers" or "Request" tab (depending on what browser you are using).

    Thanks,
    Allan

  • MadMax76MadMax76 Posts: 142Questions: 31Answers: 1

    sure - thanks!

    {
        "data[row_26741][V_Freigaben][freig_erledigt_wann]": "2022-12-02T11:58:00.986",
        "data[row_26741][V_Freigaben][freig_erledigt_durch]": "3",
        "data[row_26741][V_Freigaben][freig_erledigt]": "1",
        "data[row_26741][V_Freigaben][freig_person]": "",
        "data[row_26741][V_Freigaben][INP_ID]": "1",
        "data[row_26741][V_Freigaben][freig_angefordert_von]": "16",
        "data[row_26741][V_Freigaben][Stapelname]": "105_2211221559",
        "data[row_26741][V_Freigaben][freig_angefordert_wie]": "Firma-generell",
        "action": "edit"
    }
    

    so it seems it does not find the freig_person, although this is defined in the editor as field:

                  {label: "Freigeber", name: "V_Freigaben.freig_person", placeholder: "Bitte wählen", type: "select2"},
    

    but the problem was that the column looked like that:

     {data: "V_users.Namen", editField: "V_Freigaben.freig_person", title: "Freigeber", width: 200},
    

    I now added a column

     {data: "V_Freigaben.freig_person", title: "Freigeber_person", width: 200, visible: false},
    

    and now it works - thanks!
    Max

  • allanallan Posts: 57,737Questions: 1Answers: 9,204 Site admin

    Hi Max,

    Super - great to hear it works now :)

    Allan

  • MadMax76MadMax76 Posts: 142Questions: 31Answers: 1

    strange....it did again stop working. I also checked with other rows, they are also not defined as a column, but only in the editor

    Any further ideas you have got what could cause this?

  • allanallan Posts: 57,737Questions: 1Answers: 9,204 Site admin
    edited December 2022

    Are you inline editing perhaps? By default it will submit only the value that has changed, and since you have the validator marked as requiring that a value be submitted for that field, if you edit another field, the validator would fail.

    One option to address that (if it is the case) would be to submit the full row of data rather than just the changed value.

    The other option is to allow the optional option for the validator.

    Allan

  • MadMax76MadMax76 Posts: 142Questions: 31Answers: 1

    yes, this is inline editing. It seems strange to me, that other (unchanged and not visible/existing) columns like Stapelname or INP_ID are sent with the "old" value - only the freig_person is missing.
    I tried adding

                editor_freigaben.inline( this, {
                    submit: 'allIfChanged'
                } );
    

    in this function

          $('#liste_freigaben').on('change', 'input.editor-active', function () {
    

    But this "kills" it completely, then there is no action reported in the network-inspector at all.

  • allanallan Posts: 57,737Questions: 1Answers: 9,204 Site admin

    Are you able to PM me a link to the page so I can debug it?

    Allan

  • MadMax76MadMax76 Posts: 142Questions: 31Answers: 1
    Answer ✓

    Hi Allan,

    did some more resear ch myself...

    This works for some rows, but not for all :o :o :o

    The reason must be somewhere here:

    Editor::inst( $db, 'V_Freigaben', 'ID_freigabe')
        ->fields(
            Field::inst( 'V_Freigaben.ID_freigabe' )->set(false),
            Field::inst( 'V_Freigaben.INP_ID' ),
            Field::inst( 'V_Freigaben.Stapelname' ),
            Field::inst( 'V_Freigaben.freig_person' )
                ->options( Options::inst()
                    ->table( 'V_NeueFreigeber' )
                    ->value( 'PID' )
                    ->label( 'NamePers' )
                    ->where( function ( $q ) use ( $selectedStapelname, $selectedINP_ID  ) {
                            $q->where( 'Stapelname', $selectedStapelname )
                                ->and_where( function ( $r )  use ( $selectedINP_ID ) {
                                    $r->where( 'INP_ID', $selectedINP_ID );});
                                } )
                         )
                ->validator( Validate::minNum(
                    1,
                    '.',
                    ValidateOptions::inst()
                        ->message( 'Freigeber muss ausgewählt werden' )
                        ->allowEmpty( false )
                        ->optional( false )
                    ) ),
            Field::inst( 'V_NeueFreigeber.NamePers' ),
    

    for me it does not makes sense, but as soon as V_NeueFreigeber.NamePers is NULL (no hit in this table), the program doe not send the "V_Freigaben.freig_person", although there always is a value.

    I have now found a way around by changing V_NeueFreigeber so there always has to be a hit - still I do not understand why this happened....

    Thanks
    Max

Sign In or Register to comment.