TOPIC:

Field responding to calendar selection 3 months 1 week ago #242815

  • Topic Author
  • macross
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 68
  • Thanks: 0
Hello again!
I use a calendar field, where the user can set a specific date. I already set the validation, so that the user can only select a date in the future.
Now I need a new readonly field to respond to the date selected and display the same date but exactly one year later - how would I do that?
Thank you!

Please Log in or Create an account to join the conversation.

Field responding to calendar selection 3 months 1 week ago #242824

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 1261
  • Karma: 3
  • Thanks: 110
Hi,

Add textfield to your form and make it readonly.

Go to your form->Advanced->More options->Scripts->Initialization Script->Create code framework and put this code:
function ff_nameofform_init()
{ setInterval( calc, 500);
} // ff_nameofform_init

function calc() {
var calend = ff_getElementByName('nameoffieldcalendar').value.split("-");

var d = new Date(calend[2], calend[1]-1, calend[0]); 
d.setMonth(d.getMonth() + 12);
var mj = Number(d.getMonth()) + 1; 
ff_getElementByName('nameoffieldtext').value =d.getFullYear() + "-"+ mj + "-"+ d.getDate() ;
}
Note: Replace nameofform with name for your form (not title)
Replace nameoffieldcalendar with your name for calendar (not title)
Replace nameoffieldtext with your name for textfield (not title)

Let me know if it works for you.

Regards,
Tihana
The following user(s) said Thank You: macross

Please Log in or Create an account to join the conversation.

Last edit: Post by tihana.krivic.

Field responding to calendar selection 3 months 1 week ago #242893

  • Topic Author
  • macross
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 68
  • Thanks: 0
Hello Tihana, thanks for helping me out again :)

I use the date format %d.%m.%Y - so I changed it to
function ff_nameofform_init()
{ setInterval( calc, 500);
} // ff_nameofform_init

function calc() {
var calend = ff_getElementByName('nameoffieldcalendar').value.split(".");

var d = new Date(calend[2], calend[1]-1, calend[0]); 
d.setMonth(d.getMonth() + 12);
var mj = Number(d.getMonth()) + 1; 
ff_getElementByName('nameoffieldtext').value = d.getDate()  + "." + mj + "." + .getFullYear();
}

That works perfectly!

Nevertheless if it is a date like - let's say 01.01.2020 - that the User selected, the end date field does say 1.1.2021. Can I change that to also say 01.01.2021?

Also, when no date is selected it says NaN.NaN.NaN... putting a placeholder text doesn't change that. Anything I can do about it?

Thanks again for your great support :)

Please Log in or Create an account to join the conversation.

Field responding to calendar selection 3 months 1 week ago #242896

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 1261
  • Karma: 3
  • Thanks: 110
Hi,

I am happy that I have helped to you.
I will fix that, so i will get back to you with feedback.

Regards,
Tihana

Please Log in or Create an account to join the conversation.

Field responding to calendar selection 3 months 1 week ago #242992

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 1261
  • Karma: 3
  • Thanks: 110
Hi,

Code is here:
function ff_nameofform_init()
{ setInterval( calc, 500);
} // ff_nameofform_init

function calc() {
var calend = ff_getElementByName('nameoffieldcalendar').value.split(".");
var d = new Date(calend[2], calend[1]-1, calend[0]);
d.setMonth(d.getMonth() + 12);
var mj = ("0" +(d.getMonth()+ 1)).slice(-2);
ff_getElementByName('nameoffieldtext').value=(("0"+ d.getDate()).slice(-2))+ "."+ mj + "."+ d.getFullYear();
}

Note:
Replace nameofform with name for your form (not title)
Replace nameoffieldcalendar with your name for calendar (not title)
Replace nameoffieldtext with your name for textfield (not title)

Regards,
Tihana
The following user(s) said Thank You: macross

Please Log in or Create an account to join the conversation.

Field responding to calendar selection 3 months 1 week ago #243058

  • Topic Author
  • macross
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 68
  • Thanks: 0
Thanks again, works perfectly :)

Do you also have an idea for the second question... How to stop it from displaying NaN before a date is selected?

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.046 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!