Auto populating text from database using value that was chosen from the list.

  • maurijkmakitalo
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 0

maurijkmakitalo replied the topic: Auto populating text from database using value that was chosen from the list.

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.
#237156
  • Posts: 2463
  • Karma: 86
  • Thank you received: 333

mihaela replied the topic: Auto populating text from database using value that was chosen from the list.

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
#237169
Moderators: ForumSupporttomeperica
Time to create page: 0.045 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