public MultiselectSample() { var combo = new HtmlSelectElement { Class = "form-control", Multiple = true }; combo.AddOption("N", "North"); combo.AddOption("E", "East"); combo.AddOption("S", "South"); combo.AddOption("W", "West"); var toggle = new HtmlButtonElement { Class = "btn btn-primary", InnerText = "Toggle" }; toggle.On("click", () => { foreach (var child in combo.Children) { if (child is not HtmlOptionElement option) { continue; } option.Selected = !option.Selected; }
public void SelectProperties() { var select = new HtmlSelectElement { Size = 3 }; Assert.Equal(3, select.Size); }
public void SelectNotifyValue() { var select = new HtmlSelectElement(); select.NotifyValue(new ElementEventValue { Value = "lala" }); Assert.Equal("lala", select.Value); }
public void SelectAddOption() { var x = new HtmlSelectElement(); x.AddOption("myvalue", "this is the text"); var option = x.Options.FirstOrDefault(); Assert.NotNull(option); Assert.Equal("myvalue", option?.Value); var text = option?.Children.FirstOrDefault() as TextNode; Assert.NotNull(text); Assert.Equal("this is the text", text !.Data); }
public void OptionWithValueGetsSelected() { var select = new HtmlSelectElement { Value = "lolo" }; var option = new HtmlOptionElement { Value = "lolo" }; select.AppendChild(option); Assert.True(option.Selected); }
public void LoopSelectOptions() { var select = new HtmlSelectElement(); var option1 = new HtmlOptionElement(); var group = Element.Create("optgroup"); var option2 = new HtmlOptionElement(); group.AppendChild(option2); select.AppendChild(option1); select.AppendChild(group); Assert.Equal(new List <HtmlOptionElement> { option1, option2 }, select.Options); }
public static void ShowCookie() { //populate fields with cookie values HtmlSelectElement select = HtmlSelectElement.GetById("name"); if (select.selectedIndex != -1) { JsString selectedText = select.options[select.selectedIndex].text; HtmlSpanElement.GetById("cookieValue").innerHTML = Xdk.cache.GetCookie(selectedText); } else { HtmlSpanElement.GetById("cookieValue").innerHTML = ""; } }
public void AddSelectedOptionInGroup() { var select = new HtmlSelectElement { Value = "lolo" }; var option = new HtmlOptionElement { Value = "lolo" }; var group = new HtmlOptionGroupElement(); select.AppendChild(group); group.AppendChild(option); Assert.True(option.Selected); }
/// <summary> /// Handler for GetElementDom browser command /// </summary> private BrowserInfo ExecuteCommandSetSelectBoxIndex(int threadId, HtmlElement source, BrowserCommand command, int secondsTimeout) { if (source == null) { throw new InvalidOperationException(String.Format(EXECUTECOMMAND_REQUIRESOURCE_FORMATSTRING, "SetSelectBoxIndex")); } HtmlSelectElement select = source as HtmlSelectElement; if (select != null) { var options = select.ChildElements.FindAll("option"); if (options != null) { // remove old selected attributes foreach (HtmlElement option in options) { ((HtmlOptionElement)option).CachedAttributes.Selected = false; } // get requested index int index = Int32.Parse(command.Handler.Arguments[0].ToString()); if (index >= 0) { var newSelectedOption = select.ChildElements.Find("option", index); ((HtmlOptionElement)newSelectedOption).CachedAttributes.Selected = true; } else if (index < -1) { throw new InvalidOperationException(String.Format(EXECUTECOMMAND_NEGATIVEINDEXISOUTOFRANGE, "SetSelectBoxIndex", index)); } } } else { throw new InvalidOperationException(String.Format(EXECUTECOMMAND_REQUIRESOURCEANDTYPE_FORMATSTRING, "SetSelectBoxIndex", typeof(HtmlSelectElement).ToString())); } return(new BrowserInfo()); }
public void SetSelectedIndex() { MockCommandExecutor commandExec = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); var testPage = new HtmlPage(); HtmlSelectElement element = new HtmlSelectElement( new Dictionary <string, string>() { { "id", "button1" }, { "type", "textbox" } }, null, testPage); element.SetSelectedIndex(1); UnitTestAssert.AreEqual("SetSelectBoxIndex", commandExec.ExecutedCommands[0].Handler.ClientFunctionName); UnitTestAssert.AreEqual(1, (int)commandExec.ExecutedCommands[0].Handler.Arguments[0]); }
public static void DeleteCookie() { //remove cookie, set background, play sound, then reset background HtmlSelectElement select = HtmlSelectElement.GetById("name"); if (select.selectedIndex != -1) { JsString name = select.options[select.selectedIndex].text; Xdk.cache.RemoveCookie(name); if (Xdk.player.As <bool>() && NativeActionOf <JsString>(Xdk.player.PlaySound).As <bool>()) { Xdk.player.PlaySound("nomnomnom.mp3"); } HtmlElement.GetById("cookiemonster").style.display = "block"; SetTimeout("document.getElementById('cookiemonster').style.display='none'", 2000); UpdateDropdown(); } else { Alert("nothing selected"); } }
public static void UpdateDropdown() { HtmlSelectElement select = HtmlSelectElement.GetById("name"); JsString selectedText = null; if (select.selectedIndex != -1) { selectedText = select.options[select.selectedIndex].text; } //remove all options foreach (HtmlOptionElement option in select.options) { select.Remove(option); } //add all options JsArray <JsString> cookies = Xdk.cache.GetCookieList(); for (int i = 0; i < cookies.length; i++) { HtmlOptionElement option = new HtmlOptionElement(cookies[i], Xdk.cache.GetCookie(cookies[i]), true, true); select.Add(option, null); } //set selected if it is still there if (selectedText != null) { foreach (HtmlOptionElement option in select.options) { if (option.text == selectedText) { option.selected = true; break; } } } ShowCookie(); }
public void SelectValueChangeOnChildOptions() { var select = new HtmlSelectElement(); var opt1 = new HtmlOptionElement { Value = "a" }; var opt2 = new HtmlOptionElement { Value = "b" }; var group = new HtmlOptionGroupElement(); group.AppendChild(opt2); select.AppendChild(opt1); select.AppendChild(group); select.Value = "a"; Assert.True(opt1.Selected); Assert.False(opt2.Selected); select.Multiple = true; select.Value = "b"; Assert.True(opt1.Selected); Assert.True(opt2.Selected); }
public static void CheckSel(HtmlSelectElement obj) { int ind = obj.selectedIndex; }
public static void ChangeFont() { HtmlElement.GetById("txtSample").style.fontFamily = HtmlSelectElement.GetById("ddFonts").value; HtmlTextAreaElement.GetById("userinput").value = HtmlSelectElement.GetById("ddFonts").options[HtmlSelectElement.GetById("ddFonts").selectedIndex].text; ChangeText(); }
internal HtmlOptionsCollection(HtmlSelectElement owner) => _owner = owner;
public static void CheckSel(HtmlSelectElement obj) { int ind = obj.selectedIndex; }
public void SetUp() { _document = new HtmlDocument(); _select = (HtmlSelectElement)_document.CreateElement("select"); }
public SelectAppender(HtmlSelectElement select) { this._el = select; this.setLayout(new log4javascript.SimpleLayout()); }