Clean field-text component programmatically

Hi,

In Field-text component, how can I clean the content of the input field programmatically after the user have typed on it?
And, how can I retrieve the value in the “onChange” callback?

There aren’t examples in the guide.

@jcheung

Thanks, Carlos

Sorry, we don’t have an example at the moment.

If you are using the latest version of field-text, you should be receiving an event object back from onChange callback and event.target.value should give you the value.

Hope this helps.

Hi,

Well, I was getting the value as you say, but I asked because I don’t know if it was the best manner.
But it’s most important for me to clean the value of the FieldText from an external control, after the user has typed on it.

FYI: There is an error in the Chrome dev console when I type anything inside the field:

_Warning: FieldText is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: Facebook - log in or sign up

Thanks

Response from my developer (Matias):
It depends on if you are using dumb or smart component.
The way to do it in the “dumb” component(i.e. import { FieldText } from '@atlaskit/field-text') is to re-render the field-text with the property value empty.
There’s not a way to do it in the “smart” component (i.e. using out of the box - import AkFieldText from '@atlaskit/field-text' ) at the moment. We need to introduce a fix.

@jcheung I have a similiar problem to this, on submit of my form I need to clear all the fields but I don’t want to refresh the page. I tried re-rendering the field-text element but the fields are still dirty. what can I do

Hi all,

@atlaskit/field-text has actually been deprecated. If you are looking for a textfield - please use @atlaskit/textfield.

https://atlaskit.atlassian.com/packages/core/textfield

Cheers,
Michael

1 Like