Skip to content

reset() functionality? #1282

@John-Fratila

Description

@John-Fratila

I did:

  • [ X] Search for if my issue has already been submitted
  • [ X] Make sure I'm reporting something precise that needs to be fixed
  • [ X] Give my issue a descriptive and concise title
  • Create a minimal working example on JsFiddle or Codepen
    (or gave a link to a demo on the Selectize docs)
  • [X ] Indicate precise steps to reproduce in numbers and the result,
    like below

When a form is reset, the fields on it are restored to their initial values. Is there a similar functionality in Selectize?

Steps to reproduce:

  1. create a form with a select input with the following options: Empty Option (value=""), Option A ("a", selected), Option B ("b")
  2. on form reset handler call the clear() function of the selectize
  3. selectize the input
  4. change the option to Option B
  5. click form reset button

(I did not create a codepen because it fairly self-explanatory, I can do so if needed)

Expected result: the normal form reset functionality would be to select Option A, since that's what was selected at the time the page was loaded

Actual result: the clear() method clears the value (which is its expected behavior), so Empty Option is selected

What I'm trying to accomplish is closer to the form reset functionality. I realize I could have Option A be the empty value and then it would get selected by the clear() method, but the value has meaning for the back-end and I do not want to change business logic. Also, many times the initially selected value is dynamic, and it would be a hassle for the back-end to keep track of its initial state.

Also, I know I could call destroy() followed by selectize(), but that seems like a very inefficient way to deal with the issue.

Thoughts?

If there is no such functionality I am planning to implement it:

a reset() function that is very similar to the clear() function, including the boolean argument, but that sets the value to the original one instead of an empty one.

I'd like feedback if there is interest in me submitting a pull request with the change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions