-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
'ui-select' never gets invalid when using 'default-label' / 'default-value' props #146
Comments
Hi @LEVI-RIVKIN, Because of the like this: <ui-form>
<ui-form-field>
<ui-select
v-model="formData.selectedValue"
:options="options"
required
default-label="Select"
default-value=""
helper-text-id="select-helper"
></ui-select>
<ui-select-helper id="select-helper" :visible="!!message">
{{ message }}
</ui-select-helper>
</ui-form-field>
<ui-form-field>
<ui-button @click="onSubmit">Submit</ui-button>
</ui-form-field>
</ui-form> import { reactive, toRefs } from 'vue';
import { useValidator } from 'balm-ui';
const validator = useValidator();
const validations = [
{
label: 'Select',
key: 'selectedValue',
value: '',
validator: 'required' // Customizable
}
];
const options = [
{
label: 'A',
value: 1
}
];
const state = reactive({
formData: {
selectedValue: ''
},
message: ''
});
const { formData, message } = toRefs(state);
function onSubmit() {
const { valid, message } = validator.validate(state.formData);
state.message = message;
if (valid) {
console.log('gg');
}
} Thank you for your issue :) |
Hi @elf-mouse . Well, in my humble opinion that's not a solution but a workaround. As I mentioned I'm not in need of a workaround, I already have one which works fine. |
Hi @LEVI-RIVKIN , I will consider compatibility with this issue in the subsequent upgrade process. Thanks again~ |
Hi.
It seems like the
ui-select
element never gets theinvalid
class when using any falsy value fordefault-value
, which causes theui-select-helper
to never show as invalid.I think I've figured out why.
The material component checks whether the first value is falsy to determine whether the select is valid or not ( https://github.com/balmjs/balm-ui/blob/main/src/material-components-web/select/foundation.js#L377 ).
It seems like this line of the vue component will always cause any falsy value to become
' '
-defaultOption[this.optionValue] = this.defaultValue || ' '; // NOTE: fix floating label bug when the value is empty
( https://github.com/balmjs/balm-ui/blob/main/src/scripts/components/select/select.vue#L314 ).
So the material component will never get a falsy value for the default value, causing it to never be invalid.
My solution was to simply add the 'default' option as the first option in the options list instead of using the
default-label
/default-value
prop. But that is still a bug.Example:
Environment:
The text was updated successfully, but these errors were encountered: