-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: Fixed the default value of not selecting 'select' after switching models #2477
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 |
|---|---|---|
|
|
@@ -179,11 +179,17 @@ const render = ( | |
| const value = formFieldList.value | ||
| .map((item) => { | ||
| if (form_data[item.field] !== undefined) { | ||
| const v: any = item.option_list?.filter(i => i.value_field === form_data[item.field]) | ||
| if (v?.length > 0) { | ||
| return { [item.field]: form_data[item.field] }; | ||
| if (item.value_field && item.option_list && item.option_list.length > 0) { | ||
| const value_field = item.value_field | ||
| const find = item.option_list?.find((i) => i[value_field] === form_data[item.field]) | ||
| if (find) { | ||
| return { [item.field]: form_data[item.field] } | ||
| } | ||
| if (item.show_default_value === true || item.show_default_value === undefined) { | ||
| return { [item.field]: item.default_value } | ||
| } | ||
| } else { | ||
| return { [item.field]: item.default_value }; | ||
| return { [item.field]: form_data[item.field] } | ||
| } | ||
| } | ||
| if (item.show_default_value === true || item.show_default_value === undefined) { | ||
|
|
@@ -192,7 +198,6 @@ const render = ( | |
| 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 you've provided looks mostly clean and well-structured. However, there are a few improvements that can be made:
Here's an optimized version of your code: const render = (formFieldList: any[]): { [key: string]: any } => {
const formData = {};
const value = formFieldList.map((item) => {
if (!formData[item.field]) formData[item.field] = {};
// Use nullish coalescing for defaultValue and showDefaultValue
const defaultVal = item.showDefault ? item.defaultValue : '';
const defShow = item.showDefault ?? item.showDefaultValue;
if (defShow || !formData[item.field][item.valueField]) {
const val =
formData[item.field]?.[item.valueField] ||
item.option_list?.find(
(opt) =>
opt[item.valueField]
?.toLowerCase()
.trim() ===
form_data[item.field].toLowerCase().trim()
)?.value_field ||
defaultVal;
formData[item.field][item.valueField] = val;
}
return formData[item.field];
});
return Object.values(formData).reduce((acc, curr) => ({ ...acc, ...curr }), {});
};Key Improvements:
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| v-model="dialogVisible" | ||
| style="width: 550px" | ||
| append-to-body | ||
| destroy-on-close | ||
| :close-on-click-modal="false" | ||
| :close-on-press-escape="false" | ||
| > | ||
|
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 |
||
|
|
||
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 you provided has a minor issue that can be improved for clarity and efficiency. Specifically, there seems to be a typographical error in the line where
scorllis set totrue. It looks like it should havescroll.valueinstead.Additionally, while your changes from 30 to 40 make sense (likely increasing the threshold slightly), this change might need further justification based on context specific to your application. Here's the corrected version of the last three lines:
This correction ensures consistent use of
scroll.value, which appears to be an attribute used elsewhere in your function. If you intended to increase the sensitivity of when showing more content, consider adjusting the threshold beyond what is shown initially.