Joomla 5 Notice

We are pleased to announce that as of January 29, 2024, all of our Joomla extensions are compatible with Joomla 5.

For all who are still updateing from Joomla 3 to Joomla 4: Joomla 4 Migration instructions are available here:

There is now a separate Documentation for Visforms for Joomla 4 and for Visforms for Joomla 5!

Forum

Visforms Subscription user can ask questions in our forum. Please log in with the relevant user first.
Everybody can access the forum for reading.

Please only ask 1 question per topic.

ISO Week Number

More
5 months 1 week ago #9899 by LittleCloud
ISO Week Number was created by LittleCloud
Hi There, 

I have a form where I need to get the ISO Calendar Week number from a field that contains the current date. For example, if one of the field dates has the current date as November 27, 2023, then another number or calculation field would be pre-populated by calculating that it is week number 47 (of 52). Can your calculation field able to perform such a task? If not, is there any work-around to doing it, such as incorporating a JS snippet (see  date-fns.org/v2.16.1/docs/getWeek ). Having the field pre-populate with the correct calendar week would be preferable than to have the user do extra work to figure out which week we're on. 

Thanks.

Nelson

More
5 months 1 week ago - 5 months 1 week ago #9902 by Administrator IV
Replied by Administrator IV on topic ISO Week Number
Hello Neslon,

Here is a form with your example installed.
Form field 'birth date' is the date field for selecting a date.
Form field 'ISO Calendar Week' automatically displays the calendar week of the currently selected date according to ISO-8601 (weeks starting on Monday).

The unfilled form:
vi-solutions.de/forum-uploads/week-of-year-form_start.png

The form with a selected date and the automatically calculated calendar week:
vi-solutions.de/forum-uploads/week-of-ye...rm_date-selected.png

The form configuration, tab 'Frontend Webassets':
vi-solutions.de/forum-uploads/week-of-ye...rm-configuration.png

The function used in JavaScript comes from this website:
www.w3resource.com/javascript-exercises/...date-exercise-24.php

Your 'incorporating a JS snippet' is called 'Frontend Webassets' in Visforms:
docs.joomla-4.visforms.vi-solutions.de/e...-frontend-webassets/
All settings are made in the form:
docs.joomla-4.visforms.vi-solutions.de/e...are-made-in-the-form

A comment on your example.
Quote: 'November 27, 2023, that is week number 47'.
Unfortunately that is not correct.
November 27, 2023 is in week 48 according to ISO-8601.
Please also see here:
www.epochconverter.com/weeknumbers

The JavaScript code from the form configuration, tab 'Frontend Webassets':
Code:
jQuery(document).ready(function() {     console.log(' FEWA script loaded');     const dateFieldID   = '479'; // Visforms date field ID of field list     const numberFieldID = '555'; // Visforms number field ID of field list     jQuery(`#field${dateFieldID}`).on('change', function() {         let value = jQuery(this).val();         let parts =value.split('.');         const date = new Date(`${parts[2]}-${parts[1]}-${parts[0]}`);         jQuery(`#field${numberFieldID}`).val(getWeekISO8601(date));     });     function getWeekISO8601(dt) {         const tdt = new Date(dt.valueOf());         const dayn = (dt.getDay() + 6) % 7;         tdt.setDate(tdt.getDate() - dayn + 3);         const firstThursday = tdt.valueOf();         tdt.setMonth(0, 1);         if (tdt.getDay() !== 4) {             tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);         }         return 1 + Math.ceil((firstThursday - tdt) / 604800000);     } });

The following must be adapted to your form in the JavaScript code:
The Visforms field ID for the date field: const dateFieldID = '479';
The Visforms field ID for the week field: const numberFieldID = '555';

You can use text or number (as in the example) as the field type for the week field.

Kind regards, Ingmar

:idea: I recommend you the new and up-to-date documentation for Joomla 4:
docs.joomla-5.visforms.vi-solutions.de/en/docs/
Most of this also applies retrospectively to Joomla 3.
Please only ask 1 question per topic :-).

:idea: Ich empfehle Dir die neue und aktuelle Dokumentation für Joomla 4:
docs.joomla-5.visforms.vi-solutions.de/docs/
Das meiste gilt rückwirkend auch für Joomla 3.
Bitte immer nur 1 Frage pro Thema stellen :-).
Last edit: 5 months 1 week ago by Administrator IV.

More
5 months 1 week ago #9903 by LittleCloud
Replied by LittleCloud on topic ISO Week Number
Wow! Thank you so much Ingmar! Very well explained. I appreciate the details a lot, especially that I'm new to coding. I understand the "Frontend Webassets" much more now. Thank you.

Nelson

Moderators: Administrator AVAdministrator IV
Powered by Kunena Forum