Skip to content

New refresh method with selection of the new element #3

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dbarzin
Copy link

@dbarzin dbarzin commented Sep 22, 2024

New refresh method with selection of the new element

    refresh(data, selectedValue = null) {
        this.data = data;  // Update the data

        if (selectedValue) {
            // Find the newly added element and mark it as selected
            this.data.forEach(option => {
                if (option.value === selectedValue) {
                    option.selected = true;  // Mark this option as selected
                } else {
                    option.selected = false;  // Unselect others
                }
            });
        }

        const newElement = this._template();  // Create new HTML for the component
        this.element.replaceWith(newElement);  // Replace the current element with the new one
        this.element = newElement;  // Update the reference to the new element

        this._updateSelected();
        this._eventHandlers();  // Reattach event handlers
    }

// New refresh method with selection of the new element
    refresh(data, selectedValue = null)
@dbarzin dbarzin mentioned this pull request Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant