autocomplete with Materialize - text instead of optional image - autocomplete

I am using Materialize Autocomplete and I wonder if there is a way to use text instead of "optional image". Why? In case the text is not unique then the user will not know which one to choose. It might happen that the options will be names and there might two people with the same name and surname.
When typing my question I found out that I cannot use duplicate entries in data
data: {
"Radek": myself,
"Radek": some other Radek,
"Radoslav": 'http://placehold.it/250x250'
},
js fiddle example

When you look at the source you find the following lines relevant for the images:
autocompleteOption.append('<img src="'+ data[key] +'" class="right circle"><span>'+ key +'</span>');
and
var img = $el.find('img');
$el.html("<span>" + beforeMatch + "<span class='highlight'>" + matchText + "</span>" + afterMatch + "</span>");
$el.prepend(img);
This prevents us from using the image-attribute for anything other than images.
We can insert something like this to trick Materialize
"Radoslav": " style="display: none;">Inserted Text <br><span style="display: none`
but it will just be converted to text resulting in a option equivalent to
"Inserted Text Radoslav": none
So there is sadly nothing to be gained here.
If you are looking to insert a linebreak, however, you can use this answer on How to force Materialize autocomplete text to flow to new line?

Related

Is there any way to get specific css using swiftsoup?

Try to get CSS used using swiftsoup
let link = "<div style="background-image:URL(https://xxxx); color:blue">"
link.attr("style");
I can get all style from the div by using code link.attr
But is there any way to get specific style attr? e.g. I want to get background-image value ?
EDIT
Try using regex
let regex = "background-image:(?i)url?[(]"
print(try item.attr("style"))
print("\(try String(item.attr("style").replacingOccurrences(of: regex, with: "", options: .regularExpression)))")
The output shows: https://xxxxxx) -> Hot to add regex to delete ")" base on that regex ?

Wix: Populate repeater with external API call

I'm referring to the following video How to Create A Web App With External API Access using Wix Code & wanted to know how I would populate a repeater rather than populating a paragraph tag as shown in the youtube video mentioned above.
Basically here is the pseudocode of what I would like to achieve:
If search box is equal to null or empty
Display all crypto currencie(s)
else
Display single crypto currency
Putting the info in a repeater isn't too different than what the example already shows. Actually, when the search box is empty, the API returns an array that just needs a little playing with to get it to work with a repeater.
So, assuming you added a repeater with the ID repeater1 that contains a text element with the id result, you can make the following minor changes to the page code. You don't need to touch the backend code at all.
First, in the button1_click event handler we'll remove the code that populates the text element with the data returned from the API. Instead, we'll add an _id property to each currency object (required for the repeater) and then feed that data to the repeater.
export function button1_click(event) {
getCryptoCurrencyInfo($w("#currencyInput").value)
.then(currencyInfo => {
// add an _id property to each currency object
currencyInfo.forEach(item => item._id = item.id);
// feed the data to the repeater
$w('#repeater1').data = currencyInfo;
} );
}
Then, we can take the code for populating the text element and stick it in the repeater1_itemReady event handler. This function will run once for each currency item in the array fed to the repeater's data property. Make sure you use the properties panel to wire the function to the matching repeater event.
export function repeater1_itemReady($item, itemData, index) {
$item("#result").text = "Name: " + itemData.name + "\n"
+ "Symbol: " + itemData.symbol + "\n"
+ "Rank: " + itemData.rank + "\n"
+ "Price (USD): " + itemData.price_usd + "\n"
+ "Market Capitalization (USD): " + itemData.market_cap_usd + "\n"
+ "Percent Change 1h: " + itemData.percent_change_1h + "\n"
+ "Percent Change 24h: " + itemData.percent_change_24h + "\n"
+ "Percent Change 7d: " + itemData.percent_change_7d;
}
Notice two subtle changes to the code. First, we use $item instead of $w to select the text element. This selects the specific instance of the text element in the current repeater element. Second, we use itemData instead of currencyInfo[0]. This gives us the specific data that is associated with the current repeater element.

Mojolicious, Mojo::DOM select tag by contains text

Is there analog ":contains()"(JQuery, JSoup) selector in Mojolicious?
Selector ":contains('text') ~ td + td" work in JQuery and JSoup. How can I convert it to Mojolicious selector?
http://api.jquery.com/contains-selector/
Description: Select all elements that contain the specified text.
version added: 1.1.4jQuery( ":contains(text)" ) text: A string of text
to look for. It's case sensitive.
http://jsoup.org/apidocs/org/jsoup/select/Selector.html
:contains(text) elements that contains the specified text. The search
is case insensitive. The text may appear in the found element, or any
of its descendants.
Mojolicious analog?
Untested, but I would go in the direction of
$dom->find('*')
->grep(sub { $_->all_text =~ /text/ })
->map('following', 'td')
->map('find', 'td')
(if you have something more specific before your :contains, like at least a tag name selector, then replace the * with that, which should greatly help the performance).
Few experiment with hobbs code and I can repeat JQuery, JSoup selector result:
:contains('some string') ~ td + td
Mojo:
$dom
-> find('*')
-> grep(sub { $_ -> text =~ /some string/; })
-> map('following', '~ td + td')
-> flatten;
But, I don't think it's universal and best way to do such select. Just for start.
text
Extract text content from this element only (not including child
elements), smart whitespace trimming is enabled by default.
flatten
Flatten nested collections/arrays recursively and create a new
collection with all elements.

jQuery: Reverse inserted date in input

I'm using a jQuery plugin called masked input for inserting date in wanted format. The problem is, when someone wants to insert a date which is in format of dd.mm.yyyy and I want the input as yyyy-mm-dd, sort of reverse.
Example, if you want to insert "17.06.2013", you got in input 2013-06-17. Now, the slash part is solved, but right order can be fixed with reversing of numbers or something else?
Here is my jsfiddle: http://jsfiddle.net/dzorz/ubMMb/
HTML:
<input id="date" tabindex="1" type="text">
Script:
jQuery(function($){
$("#date").mask("9999-99-99");
});
How can it be solved? Is there some simple solution or I must look for something more serious?
How about this?
jQuery(function($){
$("#date").mask("9999-99-99", {completed:function(){
var date = this.val();
var matches = date.match(/(.*)\-(.*)\-(.*)/);
var date_format = matches[3] + "." + matches[2] + "." + matches[1];
console.log(date_format);
} });
});

Where can I find the emit() function implementation used in MongoDB's map/reduce?

I am trying to develop a deeper understanding of map/reduce in MongoDB.
I figure the best way to accomplish this is to look at emit's actual implementation. Where can I find it?
Even better would just be a simple implementation of emit(). In the MongoDB documentation, they show a way to troubleshoot emit() by writing your own, but the basic implementation they give is really too basic.
I'd like to understand how the grouping is taking place.
I think the definition you are looking for is located here:
https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/mr.cpp#L886
There is quite a lot of context needed though to fully understand what is going on. I confess, I do not.
1.Mongo's required JS version is no longer in O.Powell's url, which is dead. I cannot find it.
2.The below code seems to be the snippet of most interest. This cpp function, switchMode, computes the emit function to use. It is currently at;
https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/mr.cpp#L815
3.I was trying to see if emit has a default to include the _id key, which seems to occur via _mrMap, not shown here. Elsewhere it is initialized to {}, the empty map.
void State::switchMode(bool jsMode) {
_jsMode = jsMode;
if (jsMode) {
// emit function that stays in JS
_scope->setFunction("emit",
"function(key, value) {"
" if (typeof(key) === 'object') {"
" _bailFromJS(key, value);"
" return;"
" }"
" ++_emitCt;"
" var map = _mrMap;"
" var list = map[key];"
" if (!list) {"
" ++_keyCt;"
" list = [];"
" map[key] = list;"
" }"
" else"
" ++_dupCt;"
" list.push(value);"
"}");
_scope->injectNative("_bailFromJS", _bailFromJS, this);
}
else {
// emit now populates C++ map
_scope->injectNative( "emit" , fast_emit, this );
}
}