Disable submit on an empty input text field?

Disable submit on an empty input text field?

klinglerklingler Posts: 90Questions: 42Answers: 2

Good afternoon

Is there an option for the editor to not allow submitting a form when a specific inpute text field is empty?
Or is preSubmit the only way to go through the fields and return false in case of an empty field?

thanks in advance
richard

Answers

  • asleasle Posts: 96Questions: 28Answers: 0
    edited June 2022

    Are you talking about a "required" field? Take a look at the https://editor.datatables.net/examples/simple/simple.html and the controller staff.php

            Field::inst( 'first_name' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'A first name is required' ) 
                ) ),
    

    You can not submit the form with an empty "First name" field.

    Ah, but looking over your question again I guess you would want to disable the SUBMIT button and not just a warning? Then the preSubmit could be the way to go but take a look also at disable(). This disables buttons.

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

    Yes, just to echo @asle's comment - generally I would recommend validation be done at the server-side since client-side validation is easy to bypass. But preSubmit is the way to prevent the submission based on a given condition.

    Allan

Sign In or Register to comment.