Is there a way to specify , that these fields are non mandatory in the editor form?

Is there a way to specify , that these fields are non mandatory in the editor form?

naveensargamnaveensargam Posts: 3Questions: 2Answers: 0
edited April 2023 in Editor

Right now i want my editor form to accept null values meaning i want to specify that these fields are not required.
but it is giving me error if cant put any values.

Answers

  • rf1234rf1234 Posts: 2,809Questions: 85Answers: 406

    What error is it giving you? Post a test case please. The minimum would be to post the error message you get.

    And yes of course you can leave Editor fields empty. Editor doesn't care if fields are filled or not. You would need to use a validator if you want to display an error message.

    If you don't use a validator you need to make sure your database fields can handle empty values. Depending on your database field format you might need a setFormatter that transforms an empty field into null values. That may be relevant for date fields for example.

    Field::inst( 'dateField' )
        ->setFormatter( function ( $val, $data, $opts ) {
            if ( $val <= "") {
                return null;
            }
            return $val; //you'll probably need to convert the date as well.
        } ),
    
  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    You can attach a message to the form input.
    https://editor.datatables.net/reference/option/fields.message

  • rf1234rf1234 Posts: 2,809Questions: 85Answers: 406

    ... and a placeholder of course. But that won't resolve the error situation, I guess. You can also use client side validation. Just take a look at the list of Editor event handlers.

Sign In or Register to comment.