-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Form default value display error #1950
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,16 @@ const getData = () => { | |
| 'show-input-controls': false, | ||
| 'show-input': formValue.value.showInput | ||
| }, | ||
| props_info: { | ||
| rules: [ | ||
| { | ||
| message: formValue.value.label + '不能为空', | ||
| trigger: 'blur', | ||
| required: formValue.value.required | ||
| } | ||
| ] | ||
| }, | ||
| show_default_value: true, | ||
| default_value: formValue.value.default_value | ||
| } | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet seems to be related to configuring a reactive component that appears to manage form fields. There are a few suggestions and improvements that can be made:
Here is an optimized version based on these suggestions: const getData = () => {
return {
// ... other configurations...
form_control_options: {
hide_input_controls: !formValue.value.showInputControls,
show_input: Boolean(formValue.value.showInput),
+ required_rules: formValue.value.required ? [{
+ message: formValue.value.label || "Field is required",
+ trigger: "blur"
+ }] : [],
+ enable_default_value_showing: typeof formValue.default_value !== "undefined" && formValue.default_value !== null,
initial_form_values: formValue.toObject() // Assuming formValue.toObject returns default values from the input form
};
};This revision simplifies conditional rendering for |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,12 +181,13 @@ const render = ( | |
| if (form_data[item.field] !== undefined) { | ||
| return { [item.field]: form_data[item.field] } | ||
| } | ||
| if (item.show_default_value) { | ||
| if (item.show_default_value === true || item.show_default_value === undefined) { | ||
| return { [item.field]: item.default_value } | ||
| } | ||
| return {} | ||
| }) | ||
| .reduce((x, y) => ({ ...x, ...y }), {}) | ||
|
|
||
| formValue.value = _.cloneDeep(value) | ||
| } | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code looks generally clean and should work as intended. However, there are a few minor improvements you can make:
Here's the updated code with these suggestions: @@ -181,12 +181,15 @@ const render = (
.map(item => {
if (form_data[item.field] !== undefined) {
return { [item.field]: form_data[item.field] };
}
// Simplified conditional check
if (item.show_default_value || item.default_value !== null && item.default_value !== undefined) {
return { [item.field]: item.default_value };
}
return {};
})
.reduce((x, y) => Object.assign({}, x, y), {});
// Remove cloneDeep as we don't need to mutate the value
formValue.value = value;
}
}These changes enhance readability and maintainability while ensuring correctness. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks mostly correct. However, there are a few minor improvements you might consider:
Destructuring: You can destructure
propsinside the functional component to make it cleaner.Consistent Spacing and Indentation: Ensure consistent spacing around operators and braces for better readability.
Type Check: If
formfield.input_typeis expected to be'Slider', ensure that it's actually checked with.includes()since strings use a comma-separated list when split by,.Comments: Consider adding comments if they don't already explain the purpose of each step clearly.
Here's an improved version:
This doesn't contain any irregularities or significant optimizations needed based on the initial review, but these changes will enhance the maintainability of your codebase.