TOPIC:

Auto populating text from database using value that was chosen from the list. 11 months 2 weeks ago #237156

  • Topic Author
  • maurijkmakitalo
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 6
  • Thanks: 0
Hi,

thanks for the help, it works perfectly now.

Then actually i have one another small problem and not sure if I should make completely new topic or not but I am going to ask it here anyway.

I have two fields and in the first one it automatically fills it with current date and time. Then in the other field user fills date and time when they got the call and they are only allowed to fill the form if the time difference between them is under 24h.

I did check some javascripts for it and was thinking something like this but I am not sure if it works:

var diff = (date1 - date2) / 3600000; // To calculate time between two dates and turn it into hours.
if (diff > 24) { fail the validation); }

but I am not sure how to get data into it and make it into validation in the form.

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

Auto populating text from database using value that was chosen from the list. 11 months 2 weeks ago #237169

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 413
Hello,

The best way would be to add validation to the second calendar element.

You have to write a custom script similar as in this topic crosstec.org/en/forums/35-form-help/1261...estrict.html?start=6 .

Since you have a time field included as well, you need a different code. Actually what you need should be a combination of the topic I've linked and this one crosstec.org/en/forums/1-forums/123926-t...te-time.html?start=0 .

All in all, this is the code most similar to your case crosstec.org/en/forums/35-form-help/1259....html?start=6#234275 .
You can copy the first part and just do a little alteration in when comparing the date.

I the end, your code should look something like this:
function ff_Calendar2_validation(element, message)
{
    if(ff_getElementByName('Calendar1').value.split(" ").length != 2) {return message == '' ? "Please select date in first calendar." : message}
    if(element.value.split(" ").length != 2) {return message == '' ? "Please select date in second calendar." : message}

// first calendar
    var tim1 = ff_getElementByName('Calendar1').value.split(" ")[1];
    if(tim1.split(":").length != 2) {return message == '' ? "Please select time.n" : message}
   
    var dat1 =  ff_getElementByName('Calendar1').value.split(" ")[0];

    var vDate1 = new Date(Number( dat1.split("-")[2]),Number(dat1.split("-")[1]-1),Number(dat1.split("-")[0]),Number(tim1.split(":")[0]),Number( tim1.split(":")[1]),0).getTime();

// second calendar
    var tim = element.value.split(" ")[1];
    if(tim.split(":").length != 2) {return message == '' ? "Please select time.n" : message}
   
    var dat = element.value.split(" ")[0];
    var vDate = new Date(Number( dat.split("-")[2]),Number(dat.split("-")[1]-1),Number(dat.split("-")[0]),Number(tim.split(":")[0]),Number( tim.split(":")[1]),0).getTime();

//ADDING 24 HOURS TO THE FIRST CALENDAR ELEMENT
vDate1Added = vDate1.setDate(vDate1.getDate() + 1);
    if( vDate1Added < vDate) {
          if (message=='') message = "Entered time must be in the next 24 hours. /n";
          ff_validationFocus(element.name);
          return message;
     }
    return '';
} // ff_Calendar2_validation
NOTE: Replace every instance of Calendar2 with the name of the second calendar element. Furthermore, replace every instance of Calendar1 with the name of the first calendar element.

That should compare dates in format %d-%m-%Y %H:%M .

I hope that you will manage to apply this to your form.

Regards,

Mihaela

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

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.046 seconds

Summer Sale!

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!