In my Vue JS application form, I am facing an issue related to the pay frequency <select>
. To give some context about the situation, let me explain further.
The application form includes a <select>
box with options for users to choose their next pay day, such as Last Working day of the month, Weekly, Bi-weekly, Last Monday of the month, Last Tuesday of the month, and so on. Below, I will list all available options.
Upon selecting an <option>
, the system automatically calculates the user's Next & Following pay dates. For example, Next pay: 30/08/2019, Following pay: 27/09/2019. Users also have the flexibility to edit these fields if they wish to do so.
There are 3 input fields for Next pay date and 3 input fields for Following pay date (DD/MM/YYYY).
The problem arises with the pay frequency options for the last week of every month, like Last Monday of the month, Last Tuesday of the month, extending up to Friday. The issue occurs when, let's say, it's the last Thursday of the month, e.g., date is 29/08/2019, and then I select the option Last Monday of the month. Instead of advancing to the next month, it remains in the current month, which is incorrect since Next pay date cannot be in the past.
I am using Moment JS version 2.24.0 and Vue JS version 2.6.10. Additionally, the validation package vee-validate is already set up.
I have various methods in place to determine the user's next and following pay dates. The method payFrequencyChange that I've listed below calculates each available pay frequency option for users to select from. Although I have reviewed the code, it doesn't seem to calculate the month fields correctly based on the date.
Below is the relevant code:
// Vue instance
...
If you execute the above code at the beginning of the month, everything functions perfectly. However, if you change your computer's time/date to, let's say, 29th August 2019, and then select Last Monday - Thursday options, the Next month and Following month fields should increment. But, when choosing Last Friday, it should stay in the current month unless it's 3 days before the end of the month, in which case it should increment as well.
To better understand the scenario, I have prepared a Code Pen demo:
https://codepen.io/sts-ryan-holton/pen/rXGzox
I would appreciate any assistance regarding this matter as I did not write this entirely and am unsure how to resolve or enhance this crucial functionality.