Jump to content
UBot Underground

Loading UI HTML Dropdown from a list?


Recommended Posts

Nope the UBot staff said that it was just lucky that this ever worked and they have no plans on getting this to work again. You can just use the free file management plugin now though to do this.

Link to post
Share on other sites

Nope the UBot staff said that it was just lucky that this ever worked and they have no plans on getting this to work again. You can just use the free file management plugin now though to do this.

 

Thanks for the work around! Gonna go try it out now.

Link to post
Share on other sites

Ok tried it. Works well but the dialog is always going to be a pop up? No way to embed that on the UI HTML Panel?

Link to post
Share on other sites

Crazy as this seems like basic functionality...  

 

Hey Eddie if your reading this PLEASE BRING THIS FEATURE BACK!  I need this feature for other bots I am building. Especially for my order automation after I pull data from my DBs.

Link to post
Share on other sites

If you need to do that only once, you can do that inside "on load" command (when I gave a feature request for "on load" command I asked specifically for it, so we are able to programatically create UI before it gets loaded), so this is doable since then.

 

Here is the code:

on load("Bot Loaded") {
    clear list(%LIST Options)
    add list to list(%LIST Options, $list from text("Google,Yahoo,MSN,Bing,eBay,Craigslist,Foxnews,CNN,MSNBC,UBotBuddy", ","), "Delete", "Global")
    set(#LIST Options ROW, 0, "Global")
    set(#UI Options, "", "Global")
    loop($list total(%LIST Options)) {
        set(#UI Options, $append line to text(#UI Options, "<option value=\"{$list item(%LIST Options, #LIST Options ROW)}\">{$list item(%LIST Options, #LIST Options ROW)}</option>"), "Global")
        increment(#LIST Options ROW)
    }
}
ui html panel("<select variable=\"#VariableOfSelection\" fillwith=\"value\" style=\"width: 220px;\">{#UI Options}</select><br>
<div fillwith=\"innertext\" variable=\"#VariableOfSelection\">Ready</div>", 100)
set(#UI Var, #VariableOfSelection, "Global")

To get it working you will have to re-open UBot Studio or compile a bot for preview.

 

Also notice that I am not using "navigate" command, since that one doesn't work inside "on load" (if you use HTTP post plugin, you can even load that list from URL ).

 

Like this post if it saved your problem. :)

  • Like 2
Link to post
Share on other sites

OK, here is my work around to dynamically update the drop down,

 

NOTE: this will only work with a "Select Box"!

 

Its not perfect but it works!

ui html panel("<!DOCTYPE html>
<html lang=\"en\">
  <head>
    <meta charset=\"utf-8\">
    <meta name=\"generator\" content=\"CoffeeCup HTML Editor (www.coffeecup.com)\">
    <meta name=\"dcterms.created\" content=\"Mon, 08 Jul 2013 22:51:56 GMT\">
    <meta name=\"description\" content=\"\">
    <meta name=\"keywords\" content=\"\">
    <title></title>
    
    <!--[if IE]>
    <script src=\"http://html5shim.googlecode.com/svn/trunk/html5.js\"></script>
    <![endif]-->
  </head>
  <body>
<table>
<tr>
<td>
<button onclick=\"ubot.runScript(\'Load List()\')\">Load List</button>
</td>
</tr>
<tr>
<td>
<select variable=\"#Selected_Option\" style=\"width:300px;\" size=\"6\" onclick=\"ubot.runScript(\'Load Option()\')\" >
<optgroup label=\"Options\" variable=\"#Options\" fillwith=\"innerhtml\"></optgroup>
</select>
</td>
</tr>

</table>
  </body>
</html>", 300)
define Load List {
    set(#Options, "Item 1
Item 2
Item 3
Item 4
Item 5", "Global")
    set(#Options, "<option>{$replace(#Options, $new line, "</option><option>")}</option>", "Global")
}
define Load Option {
    set(#Loaded_Option, #Selected_Option, "Global")
    set(#Options, $replace(#Options, "<option style=\"background-color:#000; color:#00FFFF\">", "<option>"), "Global")
    set(#Options, $replace(#Options, "<option>{#Loaded_Option}</option>", "<option style=\"background-color:#000; color:#00FFFF\">{#Loaded_Option}</option>"), "Global")
}

Carl  ;)

Link to post
Share on other sites

OK, here is my work around to dynamically update the drop down,

 

NOTE: this will only work with a "Select Box"!

 

Its not perfect but it works!

Your solution will only work when you use "size > 1" parameter inside "select" tag; it won't work with normal "select" tag since output variable doesn't get updated with the value, and list is stuck to item 1.

 

Still, it works with "size > 1" because the item is always selected, so it's always forcing UBot variable to the selected value, and I think it's safe to use if you don't mind height.

 

My solution works since HTML for UI is created before UI gets loaded.

Link to post
Share on other sites

If you need to do that only once, you can do that inside "on load" command (when I gave a feature request for "on load" command I asked specifically for it, so we are able to programatically create UI before it gets loaded), so this is doable since then.

 

Here is the code:

on load("Bot Loaded") {
    clear list(%LIST Options)
    add list to list(%LIST Options, $list from text("Google,Yahoo,MSN,Bing,eBay,Craigslist,Foxnews,CNN,MSNBC,UBotBuddy", ","), "Delete", "Global")
    set(#LIST Options ROW, 0, "Global")
    set(#UI Options, "", "Global")
    loop($list total(%LIST Options)) {
        set(#UI Options, $append line to text(#UI Options, "<option value=\"{$list item(%LIST Options, #LIST Options ROW)}\">{$list item(%LIST Options, #LIST Options ROW)}</option>"), "Global")
        increment(#LIST Options ROW)
    }
}
ui html panel("<select variable=\"#VariableOfSelection\" fillwith=\"value\" style=\"width: 220px;\">{#UI Options}</select><br>
<div fillwith=\"innertext\" variable=\"#VariableOfSelection\">Ready</div>", 100)
set(#UI Var, #VariableOfSelection, "Global")

To get it working you will have to re-open UBot Studio or compile a bot for preview.

 

Also notice that I am not using "navigate" command, since that one doesn't work inside "on load" (if you use HTTP post plugin, you can even load that list from URL ).

 

Like this post if it saved your problem. :)

 

 

Thanks for this work around Ubotdev. I will give it a try as well.

 

@Kreatus - Yes the $dropdown dialog works but aesthetically it bothers me as it's a floating popup that closes everytime you make a selection.  Or am I missing a work around with it as well?

Link to post
Share on other sites

I got it

 

a bit ghetto since there is a flicker but still it works..

Essentially you set a blank option at the top and set a variable and fill it with innertext. On the dropdown itself make a onchange="ubot.runScript('scriptName')" and set the variable of the blank option to the variable of the dropdown.

 

The code is a bit messy since I was mashing up part of the code found in this thread and my own but you will get the idea:

 

EDIT: Got rid of the flicker now it looks flawless  :D

navigate("http://ubotsandbox.com/ubot-simple-list.php", "Wait")
set(#mydropdown, $scrape attribute(<id="links2scrape">, "innertext"), "Global")
set(#mydropdown, "<option>{$replace(#mydropdown, "
", "</option>
<option>")}</option>", "Global")
ui html panel("</form>
<select variable=\"#selectOption\" onchange=\"ubot.runScript(\'changeDD\')\" style=\"width: 220px;\" fillwith=\"value\">
<option variable=\"#optionVariable\" fillwith=\"innertext\"></option>
<optgroup variable=\"#mydropdown\" fillwith=\"innerhtml\"></optgroup>
</select>
</form>", 100)
define changeDD {
    set(#optionVariable, #selectOption, "Global")
}

Link to post
Share on other sites

I tested it a lot and sometimes it would switch back and flicker. So in the define I looped it 10 times to set the variable. This will make it flicker sometimes but it will always display the correct selection at the top instead of sometimes switching back.

Still a bit ghetto but better than nothing.

Link to post
Share on other sites

The solution that I provided above won't flicker, since it gets rendered on load and it acts like a hardcoded HTML.

 

I somehow skipped over your post but this solution is for sure better - thanks.

Link to post
Share on other sites

I somehow skipped over your post but this solution is for sure better - thanks.

 

The only down side of it is that you can't use browser inside "on load", so you can't get data like that, although I think you should be able to use HTTP post plugin for example (but that was not topic of discussion I think).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...