question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Label of dropdown picker on controler.reset() does not reset

See original GitHub issue

Describe the bug I have two dropdowns:

const [lang, setLanguage] = useState(null);
const [lib, setLib] = useState('');
const [langOptions, setLangOptions] = useState(str.dataLanguage.en);

let languageControler;

const libraryChange = val => {
    setLib(val)
    let options = pickLangOptions(val)
    setLangOptions(options)
  }
const pickLangOptions = (lib)=>{
    switch (lib) {
      case 'hanoi': return str.dataLanguage.viVN;
      case 'bukarest': return str.dataLanguage.enGB;
      case 'newdelhi': return str.dataLanguage.enGB;
      default: return str.dataLanguage.en;
    }
  }



<View>
  <DropDownPicker
    items={libraryItems}
    onChangeItem={item=>{
                libraryChange(item.value);
                languageControler.reset()
              }}
  />
</View>
<View>
  <DropDownPicker
    controler={ins=>languageControler=ins}
    items={languageItems}
    onChangeItem={item => {
                setLanguage(item.value)
                // console.log({item});
              }}
  />
</View>
  

when i picked language, and then i change library, i expected the value picked to be null (which is as expected) but the label persist to be the picked language

To Reproduce as written above

Expected behavior The label should be reset as well

Info (please complete the following information):

  • OS: [ Android]
  • Package version [e.g. 30]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
hossein-zarecommented, Apr 12, 2021

I reviewed your PR but is not mergeable because the reset method of the controller works well. Demo (Single): https://snack.expo.io/VVMJKW27d Demo (Multiple): https://snack.expo.io/81Idcp-y_

Please try this code:

const [lib, setLib] = useState(null); // Must be null
const languageControlerRef = useRef(null);

...

<DropDownPicker
    defaultValue={lib} // Never do this:   defaultValue: {null}
    items={libraryItems}
    onChangeItem={item=>{
        libraryChange(item.value);
        languageControlerRef.current.reset();
    }}
/>

<DropDownPicker
    defaultValue={lang}
    controler={instance => languageControlerRef.current = instance}
    items={languageItems}
    onChangeItem={item => {
        setLanguage(item.value);
    }}
 />
1reaction
hkar19commented, Feb 3, 2021

oh right thank you. I have modified version of your multiple dropdown here that works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

hossein-zare/react-native-dropdown-picker - reset the label
Describe the bug how can i reset the label of picker ? please help ... i want reset the label but i have...
Read more >
react native - Reset a selectpicker by clicking on a button
According to a github issue, setting the value to null should reset the selection, but unfortunately that doesn't seem to work.
Read more >
Solved: Reset field and show error - Power Platform Community
Solved: Hi Can somebody help me how to achieve this scenario: I have a date picker. in the date picker i want to...
Read more >
Reset Values After A Calculation +… | Apple Developer Forums
Hello again. My app calculates as expected in every manner except that when I change the picker options, it internalizes the user input...
Read more >
Form Datepicker | Components - BootstrapVue
By default, clicking on the today or reset button will also close the calendar popup, unless the prop no-close-on-select is set. Date picker...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found