Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
react-admin-cubicweb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cubicweb
react-admin-cubicweb
Commits
b96548931ff8
Commit
b96548931ff8
authored
4 years ago
by
Frank Bessou
Browse files
Options
Downloads
Patches
Plain Diff
feat: Make formHelper.getInputProps handle default values
parent
79e4ae8409ae
No related branches found
No related tags found
1 merge request
!15
Topic/default/default values
Pipeline
#39771
passed
4 years ago
Stage: checks
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/ra-cubicweb/src/__tests__/createFormHelpers.ts
+11
-0
11 additions, 0 deletions
packages/ra-cubicweb/src/__tests__/createFormHelpers.ts
packages/ra-cubicweb/src/createFormHelpers.ts
+5
-2
5 additions, 2 deletions
packages/ra-cubicweb/src/createFormHelpers.ts
with
16 additions
and
2 deletions
packages/ra-cubicweb/src/__tests__/createFormHelpers.ts
+
11
−
0
View file @
b9654893
...
...
@@ -7,6 +7,7 @@
User
:
{
login
:
{
type
:
"
String
"
,
required
:
true
}
as const
,
address
:
{
type
:
"
String
"
}
as const
,
active
:
{
type
:
"
Boolean
"
,
default
:
true
}
as const
,
},
},
relationsDefinitions
:
[],
...
...
@@ -29,5 +30,15 @@
const
props
=
formHelpers
.
User
.
getInputProps
(
"
login
"
);
expect
(
isRequired
(
props
.
validate
)).
toBe
(
true
);
});
it
(
"
returns an 'initialValue' property when the attribute has a default value
"
,
()
=>
{
const
props
=
formHelpers
.
User
.
getInputProps
(
"
active
"
);
expect
(
props
.
initialValue
).
toBe
(
true
);
});
it
(
"
returns no 'initialValue' property when the attribute has no default value
"
,
()
=>
{
const
props
=
formHelpers
.
User
.
getInputProps
(
"
active
"
);
expect
(
props
.
initialValue
).
toBe
(
true
);
});
});
});
This diff is collapsed.
Click to expand it.
packages/ra-cubicweb/src/createFormHelpers.ts
+
5
−
2
View file @
b9654893
...
...
@@ -17,7 +17,7 @@
entityType
:
SchemaEntityTypes
<
S
>
,
attributeName
:
EntityAttributeNames
<
EntityType
>
)
{
const
entity
Schema
=
schema
.
entities
[
entityType
];
const
attribute
Schema
=
schema
.
entities
[
entityType
]
[
attributeName
]
;
const
props
:
InputProps
=
{
source
:
attributeName
,
};
...
...
@@ -21,6 +21,6 @@
const
props
:
InputProps
=
{
source
:
attributeName
,
};
if
(
entitySchema
[
attribute
Name
]
.
required
)
{
if
(
attribute
Schema
.
required
)
{
props
.
validate
=
[
required
()];
}
...
...
@@ -25,5 +25,8 @@
props
.
validate
=
[
required
()];
}
if
(
attributeSchema
.
default
!==
undefined
)
{
props
.
initialValue
=
attributeSchema
.
default
;
}
return
props
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment