TOPIC:

Add Months to Date 8 months 3 days ago #240902

  • Topic Author
  • emtbrian2000
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 18
  • Thanks: 0
Greetings,

I would like to add a user entered number of months to date and pass that to a hidden field to calculate the end date. Ex:

Purchase Date: 05/01/2020
Warranty: 12 (Months)
Warranty Expiration (Calculated): 06/01/2020

I have this code in my validation custom field for the hidden expiration date field:
function ff_warrantyexpiration_validation(element, message)
{
    pd = ff_getElementByName('purchdate').value;
	wl = ff_getElementByName('warrantylength').value;
    newdate = new Date().setMonth(pd.getMonth() + wl);
	ff_getElementByName('warrantyexpiration').value = newdate;
    return '';
} // ff_warrantyexpiration_validation

When I try to submit my form it just hangs. Any help would be greatly appreciated. Thank you.

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

Add Months to Date 8 months 2 days ago #240939

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 807
Hi,

I think the calculation itself is almost ok but the bigger problem is the fact that you are trying to achieve this using a validation.

Please use Action Script in the advanced tab using the "change" event and perform your calculations and field assignments there.

I am pretty sure this will solve the hanging problem (as long as there are no syntax issues, which I cannot see there).

Regards,
Markus

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

Add Months to Date 8 months 2 days ago #240975

  • Topic Author
  • emtbrian2000
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 18
  • Thanks: 0
Thank you. The advanced tab for the hidden element? I only see an "Initscript" there. Can you elaborate on where I can find the advanced tab and change event please?

Also it seems I posted this in the free section by mistake and not the subscriber section. Can it be moved? Thanks!

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

Last edit: Post by emtbrian2000.

Add Months to Date 8 months 1 day ago #241021

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 807
Hi,

sure, please have a look at the screenshot.



The exact location is "your element" => advanced => scroll to bottom of the settings => Actionscript.

There click on custom => check "change" (because we want to execute custom code when something changes) => click on create code framework.

Inside the generated function skeleton, right after 'case "change":' you'd have to place your custom logic that you previously tried to achieve with a validation.

Regards,
Markus
Attachments:

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

Add Months to Date 8 months 1 day ago #241026

  • TheMuffinMan's Avatar
  • TheMuffinMan
  • Offline
  • Developer
  • Developer
  • Posts: 10064
  • Karma: 167
  • Thanks: 807
Hi,

I think I did a mistake, please disregard my previous post.

Instead, please apply the following validation to your hidden input (you actually had the better idea):
function ff_NAMEOFHIDDENFIELD_validation(element, message)
{

    element.value = ff_getElementByName('NAMEOFCALENDAR');
    
    if (element.value == '') {
        if (message=='') message = element.name+" faild in my test.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    return '';
}

Please replace NAMEOFHIDDENFIELD with the name (not title) of the hidden input and replace NAMEOFCALENDAR with the name of the calendar/date field (not title).

This will then copy the calendar value to the hidden field and apply a validation at the same time.

Regards,
Markus

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

Add Months to Date 8 months 20 hours ago #241057

  • Topic Author
  • emtbrian2000
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 18
  • Thanks: 0
Thanks for the quick reply. That is certainly getting me in the right direction. Integrating with your code I used this:
function ff_warrantylength_action(element, action)
{
    switch (action) {
        case 'change':
	pd = ff_getElementByName('purchdate').value;
	wl = ff_getElementByName('warrantylength').value;
	m = pd.getMonth();
    expdate = pd.setMonth(m + wl);
	ff_getElementByName('warrantyexpiration').value = expdate;
			return '';
            break;
        default:;
    } // switch
} // ff_warrantylength_action

Using that exact code does not work. The "Next" button acts as if though it was not clicked. Playing around with the code it seems to be these two lines that hang:
m = pd.getMonth();
expdate = pd.setMonth(m + wl);

Is the date format perhaps not correct to be able to use getMonth or setMonth? Thanks again.

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

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.056 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!