If date element is not null then change another element to 3rd Dropdown selection

Bren

Member
Hello all.
I have a form with a date element that if a date is added then the user should also change the Dropdown element beside it to the 3rd drop down value. The user should do this every time; but the user forgets. So, it would be nice if during form submission or when the user selected the date that this automatically happens. My 1st thought was that maybe some JS in the date element would work or maybe during the form submission...
Regardless, I?m not sure what JS code to use (I haven?t used either option, yet). Any suggestions?
Thanks in advance.
 
Try putting a JS event on the date element, on 'change' ...

this.form.formElements.get('yourtable___yourdropdown').update('x');

... which x is the value of the dropdown option you want to select. So not '3' (for third), but the actual value of the third option.

-- hugh
 
I just tried your suggestion and it works perfectly. Thank you, Hugh.
One more question. It would be even cooler if the user selected this particular Dropdown element item and the date element (if empty) changed to today's date. Could I trouble you for your suggested JS to put within the Dropdown element to make this happen?
Thanks in advance.
 
Use on 'click' (maybe 'change', but I think that doesn't work for dropdowns in some browsers).

Code:
if (this.getValue() == '3') {
   var date = new Date();
   this.form.formElements.get('yourtable___yourdate').update(date.format('%Y-%m-%d'));
}

Replace '3' with the value you want, and yourtable___yourdate with date element name.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top