davecoffin / nativescript-filterable-listpicker

Apache License 2.0
44 stars 22 forks source link

Cant use Multiple on same Page #8

Closed LorenDorez closed 6 years ago

LorenDorez commented 6 years ago

Because the IDs for the template section are the same you cant use multiple of these on the same page.

davecoffin commented 6 years ago

Why do you multiple, just change the array supplied. In my app I have 4 different form fields with 4 different sets of data that use the same one.

LorenDorez commented 6 years ago

Thats how im recoding it to do now. And ill just have to have a flag to track which form field im using. However, would still be better IMHO to have it allow multiple objects on same page.

Is there anyway to set the itemTapped even dynamically?

davecoffin commented 6 years ago

Just track what list you're showing and handle it in the itemTapped.

davecoffin commented 6 years ago

I'm not going to handle this differently, having a bunch of these on one page would not be good for performance, when you can simply handle it in the code. Just do something like:


public showCountryChooser() {
    this.shownList = 'countries';
    this.pickerSourceArray = ["USA","Finland"....];
    getViewById('myfilter').show();
}

public onFilterItemTapped(event) {
    if (this.shownList == 'countries') {
        // update your country selected
    } else if  (this.shownList == 'states') {
        // update your state selected
    }
}
LorenDorez commented 6 years ago

This is how im doing it now. Is there a way to update the ItemTappedEvent in code behind? That way i can just have several itemTappedEvents and setup them when i set the new datasource?

davecoffin commented 6 years ago

Yea, exactly like above. More context below.

publicprivate countries = ["countries.."]
private states = ["states.."]
private whatevers = ["whatevers.."]

private showList;

public showCountryChooser() {
    public itemsToShow = this.countries;
    this.shownList = 'countries';
    getViewById('myfilter').show();
}

public itemTapped(event) {
    if (this.shownList == 'countries') {
        this.handleChosenCountry(event);
    } else if (this.shownList == 'states') {
        this.handleChosenState(event);
    } else if (this.shownList == 'whatevers') {
        this.handleChosenWhatevers(event)
    }
}

private handleChosenCountry(event) {
    // set the selected country
}

private handleChosenState(event) {
    // set the selected state
}

private handleChosenWhatever(event) {
    // set the selected whatever
}