-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: The form must be filled out to trigger verification, and the verification prompt is not eliminated after assignment #1943
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 |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| <template> | ||
| <div class="radio_content" :style="radioContentStyle"> | ||
| <el-row :gutter="12" class="w-full"> | ||
| <template v-for="(item,index) in option_list" :key="index"> | ||
| <template v-for="(item, index) in option_list" :key="index"> | ||
| <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12"> | ||
| <el-card | ||
| :key="item.value" | ||
|
|
@@ -21,9 +21,10 @@ | |
| </div> | ||
| </template> | ||
| <script lang="ts" setup> | ||
| import { computed, ref } from 'vue' | ||
| import { computed, ref, inject } from 'vue' | ||
| import type { FormField } from '@/components/dynamics-form/type' | ||
| import { useFormDisabled } from 'element-plus' | ||
| import { useFormDisabled, formItemContextKey } from 'element-plus' | ||
|
|
||
| const inputDisabled = useFormDisabled() | ||
|
|
||
| const props = defineProps<{ | ||
|
|
@@ -37,11 +38,14 @@ const props = defineProps<{ | |
| modelValue?: any | ||
| disabled?: boolean | ||
| }>() | ||
|
|
||
| const elFormItem = inject(formItemContextKey, void 0) | ||
| const selected = (activeValue: string | number) => { | ||
| emit('update:modelValue', activeValue) | ||
| if (elFormItem?.validate) { | ||
| elFormItem.validate('change') | ||
| } | ||
| } | ||
| const emit = defineEmits(['update:modelValue']) | ||
| const emit = defineEmits(['update:modelValue', 'change']) | ||
| const width = ref<number>() | ||
| const radioContentStyle = computed(() => { | ||
| if (width.value) { | ||
|
|
@@ -55,11 +59,7 @@ const radioContentStyle = computed(() => { | |
| } | ||
| return {} | ||
| }) | ||
| const resize = (wh: any) => { | ||
| if (wh.height) { | ||
| width.value = wh.width | ||
| } | ||
| } | ||
|
|
||
| const textField = computed(() => { | ||
| return props.formField.text_field ? props.formField.text_field : 'key' | ||
| }) | ||
|
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. This code appears to be functioning correctly for the intended purpose of displaying a list of radio button options based on the
Here’s an updated version with a focus on making the code cleaner and more maintainable: <template>
<div class="radio_content" :class="{ [textField]: true, disabled: disabled }">
<el-row :gutter="12" class="w-full">
<template v-for="(item, index) in option_list" :key="item.value">
<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
<el-card
:key="item.value"
@click="selected(item.value)"
:disabled="inputDisabled || disabled"
>
{{ item[textField] }}
</el-card>
</el-col>
</template>
</el-row>
</div>
</template>
<script lang="ts" setup>
import { computed, ref, inject } from 'vue'
import type { FormField } from '@/components/dynamics-form/type'
import { useFormDisabled, formItemContextKey } from 'element-plus'
// Remove unused import
// const inputEnabled = useFormDisabled()
const props = defineProps<{
modelValue?:
| string
| number
| boolean
| null
| undefined
| Array<string | number | boolean | null | undefined>
disabled?: boolean
}>()
const elFormItem = inject(formItemContextKey)
const selected = (value: string | number | boolean) => {
emit('update:modelValue', value)
// Validate the checkbox immediately
if ((elFormItem as Record<string, any>)?.validate) {
(elFormItem as Record<string, any>).validate('change')
}
}
const emit = defineEmits(['update:modelValue', 'change'])
const textField = computed(() => {
return props.formField.text_field ? props.formField.text_field : 'key'
})
</script>
<style scoped>
.radio_content.key {
color: #007FFF; /* Example color */
}
.disabled {
opacity: 0.6;
}
</style>Key Changes:
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,9 @@ | |
| </div> | ||
| </template> | ||
| <script lang="ts" setup> | ||
| import { computed } from 'vue' | ||
| import { computed, inject } from 'vue' | ||
| import type { FormField } from '@/components/dynamics-form/type' | ||
| import { useFormDisabled } from 'element-plus' | ||
| import { useFormDisabled, formItemContextKey } from 'element-plus' | ||
| const inputDisabled = useFormDisabled() | ||
| const props = defineProps<{ | ||
| formValue?: any | ||
|
|
@@ -26,9 +26,12 @@ const props = defineProps<{ | |
| // 选中的值 | ||
| modelValue?: any | ||
| }>() | ||
|
|
||
| const elFormItem = inject(formItemContextKey, void 0) | ||
| const selected = (activeValue: string | number) => { | ||
| emit('update:modelValue', activeValue) | ||
| if (elFormItem?.validate) { | ||
| elFormItem.validate('change') | ||
| } | ||
| } | ||
| const emit = defineEmits(['update:modelValue']) | ||
|
|
||
|
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. In the provided Vue.js component:
Here’s your revised code snippet with some of these corrections applied: <template>
<div>
<!-- Your template content -->
</div>
</template>
<script lang="ts" setup>
import { computed, inject } from 'vue';
import type { FormField } from '@/components/dynamics-form/types';
const inputDisabled = useFormDisabled();
const props = defineProps<{
formValue?: any;
};
- const emit = defineEmits(['update:modelValue']);
+
// Inject necessary context key
const elFormItem = inject(formItemContextKey);
const selected = async (activeValue: string | number) => {
await emit('update:modelValue', activeValue);
// Check if form item exists before validating to avoid errors
if (elFormItem && elFormItem.validate) {
await elFormItem.validate('change');
}
};
defineEmits(['update:modelValue']);
</script>Explanation:
|
||
|
|
||
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 is generally clean and concise, but there's a small issue with the
rulescomputed property. If no rules are provided viaprops_info.value.rules, it currently returns an empty object instead of using the default values specified in the comments (message: errMsg.value). You can update this to use those defaults properly:Additionally, you may want to log some debugging information if something goes wrong during the execution to help identify issues in further checks.
This change ensures that the function behaves as expected when no rules are provided, which might be important depending on your application logic.