Skip to content

Commit

Permalink
packages:js:add-maxLength-to-formField
Browse files Browse the repository at this point in the history
  • Loading branch information
Voldemat committed Sep 14, 2023
1 parent c720a73 commit 483cbca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/js/src/cli/__tests__/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ spec:
required: true
type: login
errorMessage: null
maxLength: 40
password:
type: password
Expand Down Expand Up @@ -70,6 +71,7 @@ export const formExpectedCode = `export const RegistrationForm = {
required: true,
type: "login",
errorMessage: null,
maxLength: 40,
placeholder: null,
helperMessage: null,
typeSpec: {
Expand All @@ -84,6 +86,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: "Invalid",
placeholder: "password",
helperMessage: null,
maxLength: null,
typeSpec: {
type: "int",
max: 100,
Expand All @@ -96,6 +99,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: null,
placeholder: null,
helperMessage: null,
maxLength: null,
typeSpec: {
type: "float",
max: null,
Expand All @@ -108,6 +112,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: null,
placeholder: null,
helperMessage: null,
maxLength: null,
typeSpec: {
type: "date",
allowOnly: null
Expand All @@ -119,6 +124,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: null,
placeholder: null,
helperMessage: null,
maxLength: null,
typeSpec: {
type: "date",
allowOnly: "future"
Expand All @@ -130,6 +136,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: null,
placeholder: null,
helperMessage: null,
maxLength: null,
typeSpec: {
type: "time",
allowOnly: "future"
Expand All @@ -141,6 +148,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: null,
placeholder: null,
helperMessage: null,
maxLength: null,
typeSpec: {
type: "datetime",
allowOnly: "future"
Expand All @@ -152,6 +160,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: null,
placeholder: null,
helperMessage: null,
maxLength: null,
typeSpec: {
type: "image",
minSize: null,
Expand All @@ -176,6 +185,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: null,
placeholder: null,
helperMessage: null,
maxLength: null,
typeSpec: {
type: "file",
minSize: null,
Expand All @@ -192,6 +202,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: null,
placeholder: null,
helperMessage: null,
maxLength: null,
typeSpec: {
type: "enum",
itemType: "city",
Expand All @@ -208,6 +219,7 @@ export const formExpectedCode = `export const RegistrationForm = {
errorMessage: null,
placeholder: null,
helperMessage: null,
maxLength: null,
typeSpec: {
type: "union",
types: ["login","password"],
Expand Down
4 changes: 3 additions & 1 deletion packages/js/src/generators/js/formAstFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export class FormAstFactory {
)
}

buildFormFieldValue (value: string | boolean | TypeSpec | null): any {
buildFormFieldValue (
value: string | boolean | TypeSpec | null | number
): any {
if (!(value instanceof Object)) {
return this.baseAstFactory.buildLiteral(value)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/js/src/schema/defs/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"helperMessage": {
"type": ["string", "null"],
"default": null
},
"maxLength": {
"type": ["integer", "null"],
"default": null
}
},
"required": [
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/spec/types/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface FormFieldSpec {
placeholder: string | null
errorMessage: string | null
helperMessage: string | null
maxLength: number | null
}
export interface FormMetadata {
name: string
Expand Down

0 comments on commit 483cbca

Please sign in to comment.