Need multiple validators on Field::inst()

Need multiple validators on Field::inst()

daniegloydaniegloy Posts: 35Questions: 12Answers: 5

Is there a way to combine validators on a single field?

include( "./php/DataTables.php" );
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;
Editor::inst( $db, 'abcauto_stock' )
->fields(
             Field::inst( 'StockNr')->validator( 'Validate::minMaxNum', array(
                                    'required' => true,
                                    'min' => 1,
                                    'max' => 99999999999,
                                    'message' => 'Please enter a number between 1 and 99999999999'
                                ))   
                                ->validator(function ($val){
                                          //function
                                             } ),




This question has an accepted answers - jump to answer

Answers

  • btreebtree Posts: 99Questions: 14Answers: 11

    Hi,

    yes and you have already done it.

    .....
      Field::inst( 'uc_users.email' )
        ->validator( 'Validate::notEmpty' )
        ->validator( 'Validate::minMaxNum', array(
                                        'min' => 1,
                                        'max' => 99999999999,
                                        'message' => 'Please enter a number between 1 and 99999999999'
                                    ))
        ->validator(function ($val){ //function
                                    } ),
    .....
    
  • daniegloydaniegloy Posts: 35Questions: 12Answers: 5

    for some reason my minMaxNum validator when added freezes up all of my input fields after submit . And when i remove it, all input fields work again

    Field::inst( 'StockNr')
                                    ->validator( 'Validate::minMaxNum', array(
                                        'min' => 1,
                                        'max' => 99999999999,
                                        'message' => 'Please enter a number between 1 and 99999999999'
                                    ))
                                    ->validator( 'Validate::notEmpty' ) 
                                    ->validator(function ($val){
    
    
                                    }),
    
    
    
  • allanallan Posts: 61,776Questions: 1Answers: 10,112 Site admin

    What do you mean by "freezes up" - is there an error message from the server or something else? Can you link to a page showing the issue please?

    Allan

  • daniegloydaniegloy Posts: 35Questions: 12Answers: 5

    http://www.abiapps.co.za/allan/ my test server. PLease see inline editing "freez" when

     ->validator( 'Validate::minMaxNum', array(
                                        'min' => 1,
                                        'max' => 99999999999,
                                        'message' => 'Please enter a number between 1 and 99999999999'
                                    ))
    
    
    

    added

  • allanallan Posts: 61,776Questions: 1Answers: 10,112 Site admin
    edited February 2016

    I'm afraid I don't see the issue. I can edit stock numbers on your page without any issue (I put them back to how they were).

    The page is making a lot of Ajax requests. 2 or more per second.

    Allan

  • daniegloydaniegloy Posts: 35Questions: 12Answers: 5

    Hi Allan,

    Sorry, i should have specified that "stock Number" containing the validators works fine, but all of the other inputs freeze when values are changed. Concerning the 1 sec ajax calls on data refresh, i have multiple users editing data on the same datatables, a row gets a "locked" value when being edited and that row is then set to blur, to prevent other users from editing the same row, What would you suggest on the subject of realtime updates of table data, 1sec ajax calls is the only way that i was able to solve this so far, i know its putting stain on the server , but im running into deadlines, and will focus on another solution for realtime update when i have solved priority problems .

    In the current table , try and change the date value of 'date on stock' , here you will see the 'freeze' with no errors, and the bubble getting stuck until exit button is pressed and no values have been changed.

  • allanallan Posts: 61,776Questions: 1Answers: 10,112 Site admin
    Answer ✓

    There is an error - but it is coming from a field that isn't being edited, thus the error won't be shown.

    When I submit an edit on the "Registration (New)" column I get the following back from the server:

    {
        "fieldErrors": [{
            "name": "StockNr",
            "status": "Please enter a number between 1 and 99999999999"
        }],
        "data": []
    }
    

    However the client-side didn't submit anything for the stock number:

    action:edit
    data[row_16][REGNR]:Try To Change1
    

    Could you show me the full PHP you are using please?

    Allan

This discussion has been closed.