SnelleJelle
SnelleJelle

Reputation: 963

unable to validate DateType

Here's what I have:

In my route I create a default entity. "startdate" and "enddate", both date objects.

/**
 * @Route("/vacature/nieuw", name="create_vacancy")
 */
public function createVacancyAction(Request $request)
{
    $vacancy = new Vacancy();
    $vacancy->setStartdate(new \DateTime())
        ->setEnddate(new \DateTime());
    $form = $this->createForm(VacancyType::class, $vacancy);

    // check if valid and persist or whatever
}

In my VacancyType I set the date constraint for both my date fields like so:

->add("startdate", DateType::class, array(
            "widget" => "single_text",
            "constraints" => array(
                new Date(array(
                    "message" => "vacancy.date.message"
                )),
                new GreaterThanOrEqual("today")
            )
        ))

The dates are pre-filled in html in a yyyy-mm-dd format which is how I want them to.

Then, without editing the html field I receive this error upon submitting the form: enter image description here

Upvotes: 0

Views: 86

Answers (1)

SnelleJelle
SnelleJelle

Reputation: 963

found it! seemed I tried the constraint new GreaterThanOrEqual("startdate"). Thinking it would refer to my startdate....sadly it doesn not :(

Upvotes: 1

Related Questions