Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want you to add a submenu to the item selection of the whitelist. #1016

Closed
rnrnstar2 opened this issue Apr 18, 2022 · 5 comments
Closed

I want you to add a submenu to the item selection of the whitelist. #1016

rnrnstar2 opened this issue Apr 18, 2022 · 5 comments

Comments

@rnrnstar2
Copy link

I want to dynamically change the value of key by selecting a submenu when selecting tagdata.

Specifically, it's time to decide on a date format.
{
date: "2022-04-22",
format: "yyyy / MM / dd"
}

{
date: "2022-04-22",
format: "MM-dd"
}

I am developing an app that converts text created with tagrify on an aws server and sends a message to SNS.
I think that it is necessary to set the date to be sent in the whiteList of tagrify when sending in the "MM-dd" format.
If it is not a submenu, the UI is not ideal, so I would like to ask you to implement a submenu.

スクリーンショット 2022-04-18 13 59 45

@yairEO
Copy link
Owner

yairEO commented Apr 18, 2022

Hi @rnrnstar2, that isn't possible out-of-the-box and is complex to achieve, although not impossible.

It requires adding custom items (with Tagify templates) and attach hover events and logic which will show/hide the sub-menus...
The current positioning method does not support this

@rnrnstar2
Copy link
Author

I created a sandbox.
I created it like this, but it doesn't take effect when I click it.
How do I write the code and it works?

In the firstLevel menu, select a category and assume a drop menu where various tagdata are displayed in that category.

I'm sorry I'm Japanese and I'm not good at English.

https://codesandbox.io/s/tagify-react-issue-template-forked-xpkv5b?file=/src/index.js

@yairEO
Copy link
Owner

yairEO commented Apr 19, 2022

It's OK, I'm also not a native English speaker

Tagify is automatically adding tagifysuggestionidx property each dropdown item (which is something you cannot add yourself)

createListHTML( optionsArr ){
return extend([], optionsArr).map((suggestion, idx) => {
if( typeof suggestion == 'string' || typeof suggestion == 'number' )
suggestion = {value:suggestion}
var value = this.dropdown.getMappedValue(suggestion)
suggestion.value = value && typeof value == 'string'
? escapeHTML(value)
: value
var tagHTMLString = this.settings.templates.dropdownItem.apply(this, [suggestion, this])
// make sure the sugestion index is present as attribute, to match the data when one is selected
tagHTMLString = tagHTMLString
.replace(/\s*tagifySuggestionIdx=(["'])(.*?)\1/gmi, '') // remove the "tagifySuggestionIdx" attribute if for some reason it was there
.replace('>', ` tagifySuggestionIdx="${idx}">`) // add "tagifySuggestionIdx"
return tagHTMLString
}).join("")
}

image

I am unsure if this can even work even if the submenu items will have the tagifysuggestionidx attribute but I will try.

It would take me some days, as I'm currently on vacation...

@rnrnstar2
Copy link
Author

So that's it.
I'm okay if it takes time.
Thank you for your cooperation:)

@yairEO
Copy link
Owner

yairEO commented Apr 22, 2022

I would suggest you to modify the createListHTML method and use your own:

https://jsbin.com/dehaduw/edit?css,js,output

Keep in mind that the number of suggestions should not be above the number of items in the whitelist, and so the idx in the above function must match to the index of the optionsArr argument, which is basically the filtered version of your whitelist.

Then you can simply remove the last part and add it yourself manually in the template (where tagifySuggestionIdx is assigned) and do that manually in your template (don't forget to pass idx to the template function)

This is a bit complex but not by much. The only problem is to write the createListHTML function logic which groups certain items together

@yairEO yairEO closed this as completed Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants