Select All Nodes that have been searched for (that are visible)? - react-dropdown-tree-select

Is there any way to select all of the nodes that have been searched for? I can see that there is a way to select all of the nodes but I want to be able to 'Select All' but only for the nodes that I have searched for?

There is onChange method with selectedNodes propery for that. See documentation.
Example:
function onChange(currentNode, selectedNodes) {
console.log(selectedNodes)
}

Related

How do I create an optional list of choices in a discord slash command?

I am creating a game using a discord bot and am in the process of switching to slash commands. I am trying to create a command to inspect an item (as in an in-game item e.g. "iron ore") and I want the player to be able to choose from a list of all items in the game while using the inspect command. I'd imagine it would look like this: /inspect iron_ore, where the iron_ore is an item select from a list. I have successfully implemented selecting from a list of members in a command, but I do not know how to get a selectable list from other sources.
In the snippet below, I have a database query that gets all of the items in the game and returns them in a list. Additionally, how can I make this optional? I would like the /inspect command to work even if the player doesn't input an item.
db_query = get_all_items_in_db()
#tree.command(name = "inspect", description = "Examine an item in more detail")
#app_commands.describe(item = "Select an item to inspect")
async def self(interaction: discord.Interaction, item: str):
await interaction.response.send_message(f"You inspect {item}!")
I've tried passing the database query into #app_commands.choices, but it does not accept lists as a datatype.
To make an argument optional, you can type annotate it as - very unsurprisingly - Optional. Alternatively, giving it a default value will work as well.
To dynamically populate the suggestions shown to a user (I think this is what you want) you can use an autocomplete. There's an example in the docs: https://discordpy.readthedocs.io/en/stable/interactions/api.html?highlight=autocomplete#discord.app_commands.autocomplete
Note that when using an autocomplete the user can only select one item, and they aren't forced to choose anything. These are only suggestions, and they can type in whatever they want.
If you don't want that, then there's also an official example for how to create select menus ("dropdowns"): https://github.com/Rapptz/discord.py/blob/master/examples/views/dropdown.py

Order search results in react-select

When using react-select, search results are ordered alphabetically by default. This is a good default but not so nice if I have an exact match that is not first alphabetically. For example, a user may have the following options:
a_react
b_react
c_react
d_react
react
With these options, the user may search for 'react' and not be any closer to selecting the option that exactly matches the search term. Is there any way to optimize for exact matches?
react-select has a prop if you want to have a custom filter - filterOption.
If you want to show better matches based on what a user queries, use match-sorter in combination with onInputChange of react-select to create a custom filter. Here's a working demo.
There are two select inputs. Type l and observe the difference in suggestions.
In react-select you can pass a filterOption property to change how the filtering works. They provide a nice api to do what you want, which is start matching from the beginning of the string rather than anywhere in the string. That would look something like this
filterOption={createFilter({ matchFrom: "start" })}
where createFilter is imported from react-select
#ron4ex has a great answer here. Just wanted to offer another similar solution as I had 1 big issue with match-sorter.
Issue with match-sorter:
My list is a list of family relationships, e.g. "mother", "mother-in-law"
match-sorter would prioritize mother-in-law over mother as I started typing. Only once it was a full match would it prioritize mother. However, react-select kept the focused option as mother-in-law.
Even if I could fix the default focus issue, I would rather "mot" match to "mother" before "mother-in-law".
Enter new solution: Fuse:
Similar implementation as match-sorter
Fuzzy search with lots of customization options
Default config sorted "mother" over "mother-in-law"
const fuse = new Fuse(relationshipTypes, { keys: ["label"] });
<Select>
onInputChange={inputValue => {
setRelationshipOptions(
fuse.search(inputValue).map(value => value.item)
);
}}
</Select>
notice the map on fuse.search as fuse returns a mutated array with the original values in an item key and a second key being the index. Hence, fuse.search().map

How to create xpath for backtracking to parent node from child node

Currently my requirement is to check the check box at class="ui-checkbox seyc-cell-checkBox-div".
The input which I have is the supplier description present at id="cellDocument2_matrix_block_0_1"
Could you please let me know how to create a Xpath for selecting the check box using the text
"../" will take you one level up. So for example, you are on certain element and you want to navigate 3 levels up in hierarchy you would have to do element.FindElement(By.xpath(../../..));
Found an xpath :
$x("//*[contains(text(),'description')]//ancestor::a/div/div[1]")
Do let me know, incase of any other better approach for location checkbox

Remove blank option after filter

My problem is when I use a custom filter on ngOptions it creates a blank option. What I want is to have the first index of the filtered array to be selected and therefore the blank option removed.
I've search this forum for similar problems, but couldn't find any posts that addressed my problem - or I'm unable to understand the answers :)
Some of the things I've tried:
ng-init="option.selectedEnd=$first"
ng-init="option.selectedEnd=oppositeEnds[0]"
ng-selected="$first"
I've created a short fiddle for you guys: Fiddle
The empty option is generated when a value referenced by ng-model doesn't exist in a set of options passed to ng-options.
If you want to get rid of the empty option just select an initial value in your controller, something like:
$scope.form.type = $scope.typeOptions[0].value;
Here is the jsFiddle: http://jsfiddle.net/MTfRD/3/
You need to select a valid model value to get rid of this empty option.

Options on all Angular Chosen (plugin) select elements disappear when any are selected

Admittedly, I know just enough about Angular to be dangerous. However, I'm fairly certain I've followed the instructions for the plugin concisely.
The issue is: whenever I select any of the options from one of my select fields using the chosen plugin (City, Nationality, Hotel, Room Type...) the result never gets populated, and the results from all the other select fields disappear. I'm fairly certain this is user error on my part - any clarification or help is much appreciated.
You can see an example here: http://casamarelanoivas.com.br/sst/test/
Thanks.
Kyle
You are binding the selected value in your list to the same model variable you are using to generate the dropdown list. So whenever you select a value from the drop down list, you are wiping out the list values.
Here is what you have:
<select ng-model="model.cities" ng-options="city.name for city in model.cities">
This is the pattern you want to use instead.
<select ng-model="selectedCity" ng-options="city.name for city in model.cities">
In your controller you can then get the selected value from $scope.selectedCity

Resources