Problem with formatters, getting week number

Wappler 4.3.2
Windows 10

Adding a formatter to get the week number, cant get this to work.
Produces an empty response in browser.

moment.js exists on the main layout page:


Any ideas??
Thanks in advance

Please check:

I just tested this solution and it works correctly. Maybe paste the code you are using so we can check what’s wrong. Also check the browser console for errors.

Hi Teodor,
Console says:
image

Also there is an error in your code:

There is no error in the code.
Can you please post the formatter code you are using on your page?

The only code I have written so far is the formatter code:
I am not parsing a value to the js yet as it is not working at this stage.

    dmx.Formatter('string', {
    getWeek: function (val) {
        return moment(val).week()
    }
});

I got this from


It uses dmx.Formatter not dmx.Formatters

I have also replaced dmx.Formatter with dmx.Formatters with no joy.

Jim, did you check the link i posted in my previous comment?

It explains that you need to add this in your page head tags after the moment.js include:

<script>
dmx.Formatters('string', {
getWeek: function(val) {
return moment(val).week();
},
getIsoWeek: function(val) {
return moment(val).isoweek();
}
});
</script>

And on the page you are using it as:

<p>{{my_date_value.getWeek()}}</p>

That’s all. But you also need to make sure that the value you are trying to format is in a valid date format.

Great Thanks Teodor
I was trying to put the js in a formatter which caused the problem.
All good now…
Thanks again

Hi Teodor,

I can get the week from the formatted date 2021-11-23, using getWeek
It returns 48.
However I am unable to getIsoWeek as I understand iso week no for 2021-11-23 value is 47.
Can you help?

Thanks

Change:

return moment(val).isoweek();

to

return moment(val).isoWeek();

in the script block in your head tags.

Cheers Teodor