Jump to content

requiredIf in form based on Datetime input


chrizz
 Share

Recommended Posts

I am currently building a form (used in template) which includes a datetime inputfield (date of birth) and a radio input (+some other inputs). What I am trying to achieve without success so far:

Based on the datetime input the radio field needs to become required.


$field = $this->modules->get("InputfieldDatetime");
$field->label = "DOB";
$field->attr("id+name","date_of_birth");
$field->attr("type","text");
$field->dateInputFormat("d.m.Y");
$field->required = 1;
$field->customError = "Birthday missing";
$form->add($field);


$field = $this->modules->get("InputfieldRadios");
$field->attr("id+name","confirmation_underage");
$field->attr("type","text");
$field->addClass("validate");
$field->addOption(1,"lorem ipsum");
$field->addOption(2,"lorem ipsum");
$field->required = 1;
$field->requiredIf = "date_of_birth>1557180000";
$field->customError = "Missing value!";
$form->add($field);

I confirmed by testing, that the requiredif works when it is dependent on a text field (e.g. first name) and the first name matches the condition. I assume that there is something fishy with the unix time stamp in that condition but I didn't find any examples. Printing the field value shows the timestamp (as integer).

 

As usual - any help is appreciated ?

 

Thanks a lot!

 

Link to comment
Share on other sites

showIf/requiredIf are computed in javascript directly based on inputfield values and conditions on datetime values are not supported. The inputfields only hold text values, which is only converted by the server to an actual timestamp.

Link to comment
Share on other sites

@LostKobrakai, that was one of my thoughts as well. But I am building a form in a frontend template without any PW javascript (at least I am not aware of that). And because of that I tested if this is probably only a backend functionality in PW admin - but as said: it works as soon as the requiredIf is related to a text field. 

But anyways: I recognized that the Datetime field has some issues anyway. It's worth fixing them first ? 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...