-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Form. Possible to set the default value and disable some fields. #1902
Comments
You may use |
You can use const firstNameInternalFieldName = "FirstNameField";
const firstNameDefaultValue = "Test_FirstName";
return (
<DynamicForm
context={this.props.context}
listId={this.props.selectedList}
listItemId={this.props.context.itemId}
onCancelled={() => { console.log('Cancelled') }}
onSubmitError={(listItem, error) => { alert(error.message); }}
onSubmitted={async (listItemData) => { console.log(listItemData); }}
onBeforeSubmit={async (listItem) => {
// Set field value in item before saving
listItem[firstNameInternalFieldName] = firstNameDefaultValue;
return false;
}}
// Disable the field (alternative to setting the disabled prop in the field override)
//// disabledFields={[firstNameInternalFieldName]}
fieldOverrides={{
// Override for the custom field. Simply pass all received props and override specific ones (like disabled and defaultValue)
[firstNameInternalFieldName]: (props: IDynamicFieldProps) => (
<DynamicField key="firstname" {...props} disabled defaultValue={firstNameDefaultValue} />
),
}}
/>
) |
This is beautiful 💕. Have you tested it? |
Category
[ ] Enhancement
[ ] Bug
[x] Question
Version
Please specify what version of the library you are using: 3.18.0
Expected / Desired Behavior / Question
How can it possible to set default value for some field in Dynamic Form and disable this field so that this value is saved on the items after saved. And in the other fields I want to enter the value manually.
Now:
Expect: (For example, make First Name field disabled and set default value)
My Dynamic Form control.
<DynamicForm context={this.props.context} listId={this.props.selectedList} listItemId={this.props.context.itemId} onCancelled={() => { console.log('Cancelled') }} onBeforeSubmit={async (listItem) => { return false; }} onSubmitError={(listItem, error) => { alert(error.message); }} onSubmitted={async (listItemData) => { console.log(listItemData); }} />
Thanks!
The text was updated successfully, but these errors were encountered: