Skip to content

Commit

Permalink
[update] move editorValidation to config
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiipylypchuk1991 committed Mar 30, 2024
1 parent c83eaae commit 7ec60b6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
1 change: 0 additions & 1 deletion docs/api/api_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ new eventCalendar.EventCalendar("#root", {
| [](api/config/js_eventcalendar_config_config.md) | @getshort(api/config/js_eventcalendar_config_config.md) |
| [](api/config/js_eventcalendar_date_config.md) | @getshort(api/config/js_eventcalendar_date_config.md) |
| [](api/config/js_eventcalendar_editorshape_config.md)| @getshort(api/config/js_eventcalendar_editorshape_config.md)|
| [](api/config/js_eventcalendar_editorvalidation_config.md)| @getshort(api/config/js_eventcalendar_editorvalidation_config.md)|
| [](api/config/js_eventcalendar_events_config.md) | @getshort(api/config/js_eventcalendar_events_config.md) |
| [](api/config/js_eventcalendar_locale_config.md) | @getshort(api/config/js_eventcalendar_locale_config.md) |
| [](api/config/js_eventcalendar_mode_config.md) | @getshort(api/config/js_eventcalendar_mode_config.md) |
Expand Down
23 changes: 19 additions & 4 deletions docs/api/config/js_eventcalendar_config_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ config?: {
timeRange?: [number, number],
defaultEventDuration?: number,

editorValidation?: (event: object) => string | false,

viewControl?: string, // "auto" | "toggle" | "dropdown" | "none"
views?: [
{
Expand Down Expand Up @@ -116,7 +118,7 @@ In the **config** object you can specify the following parameters:
- `dateClick` - (optional) defines a behavior of clicking on the date in a grid cell in the following way:
- ***true/false*** - enables/disables an ability to click on the date in a grid cell to go to the corresponding day
- ***"day" | "week" | "month" | "year" | "agenda" | "timeline"*** - a view mode to be open when a user clicks on a grid cell
- `dateTitle`- (optional) defines a date title that displays on toolbar. The callback function takes a current date and an array with date range (start-end), and must return a string value of the date title
- `dateTitle`- (optional) defines a date title that displays on toolbar. The callback function is called with a current date and an array with date range (start-end), and must return a string value of the date title:

~~~jsx {}
dateTitle: (date, [start, end]) =>
Expand All @@ -129,6 +131,15 @@ dateTitle: (date, [start, end]) =>
- `timeStep` - (optional) a step of moving an event via d-n-d
- `timeRange` - (optional) an array with start and end time of day in the "day" and "week" modes (*0-24*)
- `defaultEventDuration` - (optional) a duration of the new created event by default (without taking into account creating an event via d-n-d)
- `editorValidation` - (optional) a callback that returns and applies validation rules to editor fields. The callback is called with the event data object:

~~~jsx {}
editorValidation: event => {
console.log(event);
if (!event.text) return "Text is required";
}
~~~

- `cellCss` - (optional) a custom CSS selector to be applied to a grid cell. This property is used in any of view mode configuration objects to apply a custom style to the grid cell
- `viewControl` - (optional) defines a control to switch through the view modes. Here you can specify the following values: *"auto" | "toggle" | "dropdown" | "none"*. The *auto* value is set by default
- `views` - (optional) an array of configuration objects of the specific (custom) view modes. For each view mode you can specify the following settings:
Expand Down Expand Up @@ -187,7 +198,7 @@ views: [
// ...,
getBounds: (date) => {
const weekStart = getMonday(date);
return [weekStart, new Date(weekStart.getFullYear(), weekStart.getMonth(), weekStart.getDate() + 7);
return [weekStart, new Date(weekStart.getFullYear(), weekStart.getMonth(), weekStart.getDate() + 7)];
},
]
~~~
Expand Down Expand Up @@ -347,7 +358,7 @@ To set the **config** property dynamically, you can use the

### Example

~~~jsx {3-36}
~~~jsx {3-40}
// create Event Calendar
new eventCalendar.EventCalendar("#root", {
config: {
Expand All @@ -359,6 +370,10 @@ new eventCalendar.EventCalendar("#root", {
dimPastEvents: true,
eventVerticalSpace: 8,
dateTitle: (date, [start, end]) => `${format(start, "do")} - ${format(end, "do")} ${format(date, "LLL")}`,
editorValidation: event => {
console.log(event);
if (!event.text) return "Text is required";
},
views: [
{
id: "timeline",
Expand Down Expand Up @@ -394,4 +409,4 @@ new eventCalendar.EventCalendar("#root", {

- The ***dateClick*** property was added in v2.0.2
- The ***dateTitle***, ***eventVerticalSpace*** and ***eventHorizontalSpace*** properties were added in v2.1
- The ***eventMargin*** property was deprecated in v2.1
- The ***eventMargin*** property was deprecated in v2.1
6 changes: 5 additions & 1 deletion docs/api/config/js_eventcalendar_editorvalidation_config.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
sidebar_label: editorValidation
sidebar_label: editorValidation (Deprecated)
title: editorValidation Config
description: You can learn about the editorValidation config in the documentation of the DHTMLX JavaScript Event Calendar library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Event Calendar.
---

# editorValidation

:::warning
The `editorValidation` property was moved to the [`config`](api/config/js_eventcalendar_config_config.md) property.
:::

### Description

@short: Optional. A callback that returns and applies validation rules to editor fields
Expand Down
1 change: 0 additions & 1 deletion docs/api/overview/properties_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ description: You can explore a properties overview in the documentation of the D
| [](../config/js_eventcalendar_config_config.md) | @getshort(../config/js_eventcalendar_config_config.md) |
| [](../config/js_eventcalendar_date_config.md) | @getshort(../config/js_eventcalendar_date_config.md) |
| [](../config/js_eventcalendar_editorshape_config.md)| @getshort(../config/js_eventcalendar_editorshape_config.md)|
| [](../config/js_eventcalendar_editorvalidation_config.md)| @getshort(../config/js_eventcalendar_editorvalidation_config.md)|
| [](../config/js_eventcalendar_events_config.md) | @getshort(../config/js_eventcalendar_events_config.md) |
| [](../config/js_eventcalendar_locale_config.md) | @getshort(../config/js_eventcalendar_locale_config.md) |
| [](../config/js_eventcalendar_mode_config.md) | @getshort(../config/js_eventcalendar_mode_config.md) |
Expand Down
1 change: 0 additions & 1 deletion sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ module.exports = {
"api/config/js_eventcalendar_config_config",
"api/config/js_eventcalendar_date_config",
"api/config/js_eventcalendar_editorshape_config",
"api/config/js_eventcalendar_editorvalidation_config",
"api/config/js_eventcalendar_events_config",
"api/config/js_eventcalendar_locale_config",
"api/config/js_eventcalendar_mode_config",
Expand Down

0 comments on commit 7ec60b6

Please sign in to comment.