Orderlist needs one more feature

UI Components for React
Post Reply
rossd
Posts: 18
Joined: 26 Oct 2015, 06:51

21 Mar 2018, 00:25

I am building an application that maintains survey questions. Some questions have a list of canned responses eg Animal or Vegetable or Mineral.
I jumped on Orderlist and I am able to add new items to the list of possible responses (separate button), move them as required to get the order I require.

However, I want to have a Delete button that removes the currently selected item.

How can I find which is the currently selected item so I can remove it from the array?

Thanks

Ross
(long time Primefaces user)

rossd
Posts: 18
Joined: 26 Oct 2015, 06:51

21 Mar 2018, 03:21

Figured out a way to make it work:

Code: Select all

 <OrderList value={this.state.selectedQ1.options} 
                                               ref={(OrderList) => { this.orderList = OrderList; }}
</OrderList>
and the action handler for the delete button refers to this.orderList.state.selection :

Code: Select all

deleteOption(e) {
        let newOptions = this.state.selectedQ1.options;
        let deleteIndex = newOptions.findIndex((d)=> d == this.orderList.state.selection);
        console.log(deleteIndex,newOptions[deleteIndex] );
        newOptions.splice(deleteIndex,1);

        this.updateProperty('options', newOptions);
    }

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests