BF : Compare two hidden inputs

  • Gilles361
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
  • Posts: 176
  • Thank you received: 5

Gilles361 created the topic: BF : Compare two hidden inputs

Hi,

I have create two DATE Hidden inputs Date1 (Value= "2019-05-21 11:30", and Date2 using PHP Value : <?php return date("Y-m-d H:i") ?> >>> Result format : "2019-05-07 11:30"

1/ I would like to create another TEST hidden input to compare both dates and take a "ff_switchpage(3);" decision if Date2 < Date1.

How may I compare both dates ?
(I was thinking : Hidden Input, Initscript, Page, custom script ?)
function ff_LimiteTestDate_init()...

I'm using hidden Inputs to debug with summarize elements

Thanks for you help,
Gil
#235974
  • Posts: 2483
  • Karma: 86
  • Thank you received: 335

mihaela replied the topic: BF : Compare two hidden inputs

Hello,

Here is how you can make it work as you want.

Go to form's Advanced properties > More options > Scripts and in the Initialization script section set Type to Custom.

In the code area below put the following code:
function ff_FORMNAME_init()
{  setInterval( calc, 500);
} // ff_FORMNAME_init


function calc() {
var Date1 = Date.parse(ff_getElementByName("Date1").value); 

    var Date2 = Date.parse(ff_getElementByName("Date2").value); 
    if ( Date1 > Date2) {
       ff_switchpage(3);
       // ff_getElementByName("TEST").value = "Date2 is smaller than Date1";
    } // if
   
}
NOTE: In the code above you have to replace FORMNAME with the Name of your form.

What this code will do is it will take compare values from fields named "Date1" and "Date2" every half second and in case Date2 is smaller than Date1 it will redirect to page 3. In this case, field "TEST" isn't needed. If you want, you can assign that field a value in code as in commented line of code.

Let me know whether this is working as you wanted.
If you have more questions, feel free to ask.

Regards,

Mihaela
#235984
  • Gilles361
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
  • Posts: 176
  • Thank you received: 5

Gilles361 replied the topic: BF : Compare two hidden inputs

Hi,
Thanks,

1/ is it possible to do so in a hidden INPUT (Name : TESTDATE): within init custom script

2/ Date1 and Date 2 are hidden input elements. Should I use "Date2" or 'Date2' ? (ff_getElementByName("Date2").value)

what is the difference between "Name" and 'Name' in my ff_function?

Thanks, Gil
#236000
  • Posts: 2483
  • Karma: 86
  • Thank you received: 335

mihaela replied the topic: BF : Compare two hidden inputs

Hello,

Here are the answers to your questions:

1) Yes, it is possible to write the code in Init script of the TESTDATE field instead of in form's Initialization script.
So, just go to Advanced properties of TESTDATE field. In Intscript section set Type to Custom and check the "Form Entry" checkbox.

In the code area below put the following code:
function ff_TESTDATE_init(element, condition)
{
 setInterval( calc, 500);   
} // ff_TESTDATE_init

function calc() {
var Date1 = Date.parse(ff_getElementByName("Date1").value); 

    var Date2 = Date.parse(ff_getElementByName("Date2").value); 
    if ( Date1 > Date2) {
       ff_switchpage(2);
    } // if
   
}

That should do the trick.

2) In this case it makes no difference which quotation sign you use: " or '.
This is ok: ff_getElementByName("Date2").value

On the other hand, in this case: ff_FIELDNAME_init you shouldn't use any quotation marks. You can see an example in the code above.

Let me know whether this answers your questions and whether it is working as you wanted.

Regards,

Mihaela
#236033
  • Gilles361
  • Topic Author
  • Offline
  • Gold Boarder
  • Gold Boarder
  • Posts: 176
  • Thank you received: 5

Gilles361 replied the topic: BF : Compare two hidden inputs

Hi Mihaela,
I've the "TestDate" working OK in hidden element, but it doesn't pass the Date1 & 2 to Page2 (summarize Section)

My "Test Code", element "Initscript" (+Page Entry):

function ff_TestDate_init(element, condition){
var Date1 = Date.parse(ff_getElementByName("Date1").value);
var Date2 = Date.parse(ff_getElementByName("Date2").value);
if ( Date2 < Date1) {
ff_switchpage(3);
// Va sur le début de formulaire
} else {
// Va sur le message de formulaire fermé
ff_switchpage(2);
}
}

If I want to keep Element Value (Date1 & 2), I've to add a "NextPage > Submit Element" ...

1/ How to keep Data1 & 2 for summarize table in Page 2 or Page 1?
Should I fetch data?

2/ What is use of Initscript : "Form Entry" & "Page Entry"?
When should I check them?

3/ should I use ff_TestDate_init(element, condition) or ff_TestDate_init()?
Is it important in BF?

Thanks, Gil
#236054
  • Posts: 2483
  • Karma: 86
  • Thank you received: 335

mihaela replied the topic: BF : Compare two hidden inputs

Hello,

Here are the answers to your question:

1) I've tested this kind of behavior and it turns out that the summarize elements for Date1 and Date2 fields indeed do not get filled in. Either way, there is a solution for this. The summarize fields can be manually filled in using s piece of code.
The whole code should look like this:
  var Date1 = Date.parse(ff_getElementByName("Date1").value);
var Date2 = Date.parse(ff_getElementByName("Date2").value);
if ( Date2 < Date1) {

console.log("manji je drugi datum");
ff_switchpage(3);
// Va sur le début de formulaire
} else {
// Va sur le message de formulaire fermé

ff_switchpage(2);
jQuery(document).ready(function(){
    jQuery("#ff_elem4239").text(ff_getElementByName("Date1").value);
    jQuery("#ff_elem4244").text(ff_getElementByName("Date2").value);
    });

}
NOTE: In order for this code to work, you have to replace "ff_elem4239" and "ff_elem4244" with the ids of values of summarize elements for Date1 and Date2 in your form.

2) When you are writing an Init script for a field, you need to check either "Form Entry" or "Page Entry", or both. That defines when the script you write below will be run, when the form is entered or when you enter that specific page on which the element you are writing the script.

3) In this case you can use both ff_TestDate_init(element, condition) or ff_TestDate_init(). Usually, if you pass variables element and condition you can use them in the code.
For example, you can fetch the data from that field for which you are writing the script using "element.value". Or you could write code dependiong on the condition if you check more then one checkbox:
switch (condition) {
        case 'formentry':
            break;
        case 'pageentry':
            break;
        default:;
    } // switch

Let me know whether this resolves the issue with summarize fields and whether it answers your questions.

Regards,

Mihaela
#236108
Moderators: ForumSupporttomeperica
Time to create page: 0.068 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

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!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here