Skip to content

Set different options after initialization #176

Closed

Description

@hedderich

Hey everyone,

is there any way or interface to update the placeholder text to a different string than the one provided when initializing a MapboxGeocoder object, without creating a new instance?

When reassigning options.placeholder, the value changes, however it is not reflected in the state of the text input. Applying the same logic to the language attribute works though.

Consider this example:

const geocoder = new MapboxGeocoder({
  accessToken,
  language: 'en',
  placeholder: 'My placeholder when the app loads',
  ...
})

// user performs an action

geocoder.options.language = 'pt'
// language is set to Portuguese

geocoder.options.placeholder = 'My placeholder when the user performed an action'
// nothing happens

Activity

  1. andrewharvey commented on Jan 21, 2019

    @andrewharvey
    Collaborator

    geocoder.options isn't exposed as part of the public API https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md so there's no guarantees on what happens if you change it directly.

    The standard way to do this would be using setters/getters for each of those options, so geocoder.setPlaceholder('your placeholder'), but those haven't been implemented, only get/setProximity have been implemented.

    I can see how this would make it easier to change language without needing to remove, and re-add a new geocoder.

  2. tristen commented on Feb 28, 2019

    @tristen
    Member

    Yeah hmm, perhaps something like a geocoder.setOptions({}) could work.

  3. changed the title [-]Custom placeholder text does not update[/-] [+]Set different options after initialization[/+] on Feb 28, 2019
  4. added this to the v4.0.0 milestone on Mar 13, 2019
  5. scottsfarley93 commented on Mar 22, 2019

    @scottsfarley93

    This was addressed in #226. That work introduced get and set functions for most options set-able in the constructor. It will be in the version4 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions