restrict field date only week-day or only one day of week

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • item
    Active Community Member
    • Mar 2017
    • 1476

    restrict field date only week-day or only one day of week

    Hi,

    what's is the best way to restrict user do not enter value in a date field other than :
    - only week-day (only working day : monday->friday)
    - only thuesday (for sample)

    incredible, user fill this date field a saturday, a sunday.. and user don't work.
    Not understand user, this field is "default : today" .. i don't understand why user change this field.

    This field must be editable, because, maybe next thuesday

    Last edited by item; 03-27-2024, 08:20 PM.
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​
  • yuri
    Member
    • Mar 2014
    • 8453

    #2
    Hi Item,

    You can use API Before-Save script and check the date value.

    Code:
    if (
        dateField &&
        (
            datetime\dayOfWeek(dateField, 'Europe/Amsterdam') == 0 ||
            datetime\dayOfWeek(dateField, 'Europe/Amsterdam') == 6
        )
    ) {
        recordService\throwBadRequest("Only weekdays are allowed.");
    }
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    Working...