Skip to content

How to insert an empty value while editing entity? #48

@secit-pl

Description

@secit-pl

I have the following code, it's used to edit the contact entity:

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);

        $contacts = $this->doctrine->getRepository(Contact::class)->findAll();
        if (!$contacts) {
            $io->note('No contacts found.');

            return Command::SUCCESS;
        }

        $contact = $io->choice('Contact', $contacts);

        $this->getHelper('form')->interactUsingForm(
            ContactType::class,
            $input,
            $output,
            [],
            $contact
        );

        $this->doctrine->getManager()->flush();

        $io->newLine(2);
        $io->success('Contact changed');

        return Command::SUCCESS;
    }

The input form in console looks as follows:

image

The question is, what should I do to clear the email field value? Hitting "enter" leave the data unchanged. Entering empty space don't change anything. I'd like to set the email to empty string or to null, now it can be done?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions