Skip to content

Commit

Permalink
fix(schema-formio): allow adding additional properties for date/time …
Browse files Browse the repository at this point in the history
…formio component
  • Loading branch information
Romakita committed Apr 25, 2023
1 parent d1417b8 commit 5ea3082
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {getValue} from "@tsed/core";
import {execMapper, registerFormioMapper} from "../registries/FormioMappersContainer";

function dateToComponent(schema: any, options: any) {
Expand All @@ -8,7 +9,8 @@ function dateToComponent(schema: any, options: any) {
enableMinDateInput: false,
datePicker: {
disableWeekends: false,
disableWeekdays: false
disableWeekdays: false,
...getValue(component, "datePicker")
},
enableMaxDateInput: false,
enableTime: false,
Expand All @@ -27,7 +29,8 @@ function dateToComponent(schema: any, options: any) {
minDate: null,
disableWeekends: false,
disableWeekdays: false,
maxDate: null
maxDate: null,
...getValue(component, "widget")
}
};

Expand All @@ -47,11 +50,13 @@ function dateToComponent(schema: any, options: any) {
return {
...base,
timePicker: {
showMeridian: false
showMeridian: false,
...getValue(component, "timePicker")
},
widget: {
enableTime: true,
time_24hr: true
time_24hr: true,
...getValue(component, "widget")
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {DateFormat, DateTime} from "@tsed/schema";
import {getFormioSchema} from "../src";
import {Component, getFormioSchema} from "../src";

describe("Date integration", () => {
it("should generate date-time field", async () => {
class Model {
@DateTime()
test: Date;
}

const form = await getFormioSchema(Model);
expect(form).toEqual({
components: [
Expand Down Expand Up @@ -50,6 +51,7 @@ describe("Date integration", () => {
@DateFormat()
test: Date;
}

const form = await getFormioSchema(Model);
expect(form).toEqual({
components: [
Expand Down Expand Up @@ -99,4 +101,65 @@ describe("Date integration", () => {
tags: []
});
});
it("should generate date field with additional props", async () => {
class Model {
@DateFormat()
@Component({
datePicker: {
disableWeekends: true,
disableWeekdays: true
}
})
test: Date;
}

const form = await getFormioSchema(Model);
expect(form).toEqual({
components: [
{
datePicker: {
disableWeekdays: true,
disableWeekends: true
},
disabled: false,
enableMaxDateInput: false,
enableMinDateInput: false,
enableTime: false,
format: "yyyy-MM-dd",
input: true,
key: "test",
label: "Test",
type: "datetime",
validate: {
required: false
},
widget: {
allowInput: true,
disableWeekdays: false,
disableWeekends: false,
displayInTimezone: "viewer",
enableTime: false,
format: "yyyy-MM-dd",
hourIncrement: 1,
locale: "en",
maxDate: null,
minDate: null,
minuteIncrement: 1,
mode: "single",
noCalendar: false,
type: "calendar",
useLocaleSettings: false
}
}
],
display: "form",
machineName: "model",
name: "model",
title: "Model",
type: "form",
submissionAccess: [],
access: [],
tags: []
});
});
});
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

[travis]: https://travis-ci.org/

0 comments on commit 5ea3082

Please sign in to comment.