Home > Net >  How to remove dropdown selection in Vue on a specific condition?
How to remove dropdown selection in Vue on a specific condition?

Time:07-31

I am creating a dropdown selection (visit status) which consists of pending,canceled rejected and approved. So when it is approved, i want the dropdown selection to show canceled and rejected selection only. The this.inputs.visit_status.choices is consisted of array and object that represent visit status choices. Each array consists of display name and value For example, display name equal to PENDING and value equal to pending. Is it possible to remove the specific array if visit status is approved and show canceled and rejected value only ?

Array Example

0: {__ob__: Observer} ( pending)
1: {__ob__: Observer} ( approved)
2: {__ob__: Observer} (canceled)
3: {__ob__: Observer} (rejected)

Dropdown Selection

      this.$set(this.inputs.visit_status, "item_text", "display_name")
      this.$set(this.inputs.visit_status, "item_value", "value")
      this.$set(this.inputs.visit_status, "items", this.inputs.visit_status.choices)
      this.$set(this.visitStatusOriginal, "visit_status", item.visit_status)
      if (item.visit_status) {
        this.$set(this.inputs.visit_status, "value", item.visit_status)
        this.$set(this.inputs.visit_status, "tmp_value", {
          "display_name": item.visit_status.toUpperCase(),
          "value": item.visit_status
          })
      }

What i had tried :

I try to set a condition if the visit status value is equal to approved , i set the value according to the value but it only show one option only which is rejected only. The result that I want is to show cancel and reject options. Is there any way to improve this code ?

 if (item.visit_status == 'approved'){
          this.$set(this.inputs.visit_status, "items", this.inputs.visit_status.choices[2])
          this.$set(this.inputs.visit_status, "items", this.inputs.visit_status.choices[3])
      }

CodePudding user response:

As I understand from your description the items variable is expected to be an array.
What your code does is set a single option at a time to items instead of an array.

Please try the following code:

if (item.visit_status == 'approved') {
    this.$set(this.inputs.visit_status, "items", [this.inputs.visit_status.choices[2], this.inputs.visit_status.choices[3]]);
}
  • Related