-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
[Feature Request] Pressing the clearable icon on <v-text-field> with clearable prop sets the model to null not to empty string #4144
Comments
See also #2752 |
I can see this being added as a prop in the future, reset-value, but currently this is not considered a bug. |
This comment has been minimized.
This comment has been minimized.
You would need to extend the component and rewrite its reset functionality. |
This comment has been minimized.
This comment has been minimized.
But I have the opposite problem. I have a object from backend with null values. and if the user enters a value and clicks clearable, the value will change to an empty string instead of null. Provided that the mask is used in the field. |
It looks like there is a new prop that solves this problem now. In version > 1.1, there is a prop called |
Second an empty-string since this would be consistent with what the value is when the user clears the field by deleting its content. |
I ran into this myself today. Check out the differences in using https://codepen.io/anon/pen/EdPzBd?editors=1011 With I reported the inconsistency here: #5213 |
I "third" an empty-string as well for the same reasons. It creates problems because |
Issue just popped up on Discord again. I think it's a good idea to make this configurable, as John suggested. |
Any news about reset-value @johnleider ? Plus I would prefer not to use |
It's coming on v1.4 |
There is currently a PR open to resolve this but needs a bit more polish. Unfortunately it did not make the cut for v2 but obviously is on the radar. Thank you for your patience. |
I think in general every component should have a default 'zero' cleared state that is well documented and can be overridden. Instead of 'clearable', perhaps we can create an new property called 'resettable'. Each component would then have a value or callback function to supply the component. Additionally , the runtime could provide a few default implementations. If the function is not supplied, a default handler can simply delegate to 'clearable' This would be trivial to implement, remove the ambiguity of the clearable operation, and make the user code cleaner and smaller. <v-text-field resettable />
<v-text-field resettable='' />
<v-text-field :resettable='null' />
<v-text-field :resettable=" ()=>'' " />
<v-text-field :resettable=" ()=>null ">
<v-text-field :resettable=" ()=>undefined ">
<v-text-field :resettable=" ()=>'Default Value' ">
<v-text-field :resettable="$r_empty">
<v-text-field :resettable="$r_null">
<v-select :resettable=" ()=>[] ">
<v-select :resettable=" ()=>['a','b','c'] ">
<v-select :resettable=" ()=>null ">
<v-select :resettable="$r_array"> We can also just add this to the existing clearable property, but in that case things would break if the developer had coded |
I actually reached this today after a session of debugging to find out the I'm doing the following as a workaround, but I would like to add my voice to have a <v-select
:value="iso3"
@input="iso3=$event?$event:null"
:items="countries"
item-text="name"
item-value="iso3"
label="Country"
clearable
></v-select>
... |
This comment has been minimized.
This comment has been minimized.
I'm facing same, i.e. this json payload {
"name": "Joe",
"phone": undefined,
"cellphone": null
} would make it to backend as {
"name": "Joe",
"cellphone": null
} key if phone was set before in backend/DB, it cannot be cleared to empty/null in backend/DB since cannot post/put workaround is to use axios interceptor (or interceptor of whatever lib you're using) /**
* Add json cleaner to set undefined/null values to empty string.
* This is to prevent axios(json to string using jsonify) from removing those keys
* when converting json paylod to string.
*/
function cleanJSON(json) {
for (let key in json) {
if (json[key] === undefined || json[key] === null) {
json[key] = '';
} else if (typeof json[key] === 'object')
json[key] = cleanJSON(json[key]);
}
return json;
}
// Add a request interceptor
window.axios.interceptors.request.use(
function(config) {
if (['post', 'put', 'patch'].includes(config.method)) {
config.data = cleanJSON(config.data);
}
return config;
},
function(error) {
return Promise.reject(error);
}
); |
You are right, I just tested it. so once v-select clears to Thanks @jacekkarczmarczyk for correcting me. I edited my previous comment to correct it. |
On default values: does anyone differentiate between |
I've run into this issue on a number of different form components, as has been mentioned in this thread. Both with the While I understand using either This would help in a wide range of applications where some fields need to have their value reset to something specific for the application. For example, setting a specific field to the A blanket reset to |
So is there a workaround for this? I'm using it's value as a prop, which expects type: String and throws an error, if it gets cleared. If I add |
I'm using @input event for this problem, it will return empty string when click on clear icon:
By the way, please don't show clear icon in readonly mode @KaelWD |
Resolved in #13996 |
This fix got regressed, so the bug is still open. See link below for the offending line of code. A workaround is to reset the value when the
|
Yup as of 22/09/2023 there is a regression on this one. This is especially painful if you globally enable the "clearable" prop and have to change your api to support null and string instead of string only on all endpoints. |
Yes, looks like it regressed in c669540 |
Versions and Environment
Vuetify: 1.0.18
Vue: 2.5.16
Browsers: Vivaldi 1.96.1147.42
OS: Windows 10
Steps to reproduce
Create a
<v-text-field>
withclearable
and the model for it. Fill in some text. Press X icon (default) to clear the text, check the model.Expected Behavior
Model is an empty string
''
.Actual Behavior
Model is
null
.Reproduction Link
https://codepen.io/anon/pen/YLoaOo?editors=1111
Other comments
It gets annoying when you have String functions on that model and they return errors because they can't be applied to
null
if a user in the front-end uses the clearable icon. The bug also applies on the newest alpha.The text was updated successfully, but these errors were encountered: