Back to Blog
Xojo array of controls6/22/2023 When he’s not online, chances are he will be scuba diving … or crocheting amigurumis. Xojo has been his secret weapon and language of preference since 2018. Growing up surrounded by computers and became interested in web technologies since the dial-up connections era. Ricardo has always been curious about how things work. A menu selection can be modified after it is selected. The user can either enter text in the Combo Box or choose an item from the attached Popup Menu. You can download the example from the GitHub code repository. Combo box Xojo documentation » Combo box Combo box The Combo Box control works like a combination of a Text Field and a Popup Menu. From displaying a pending notifications counter in a WebButton, to validation errors in a WebTextField.Īdjust and play with the code to meet your needs! □ You can use these badges in different scenarios. Now, if you have a WebButton called… “AwesomeButton”, you can set its badge using this code: AwesomeButton.SetBadge("Hello!")Īnd to remove it: AwesomeButton.RemoveBadge() The content is a bit easier this time: Var js As String = "$('#" + control.ControlID + ". The method definition reads like this: Extends control As WebUIControl Did you notice we are using “control” instead of “Self”? It matches the “control” variable from the method definition.Īdd another Extension Method for removing the badges, called “RemoveBadge”. What this little sorcery does is appending a new HTML layer into our control, using some Bootstrap’s component CSS classes. Js.Add("$('#" + control.ControlID + "').append(`" + html + "`) ")Ĭontrol.ExecuteJavaScript(String.FromArray(js)) "border", "border-light", "bg-" + indicator)Ĭlasses.Add(If(caption.Length " + caption + "" Inside, paste the method contents: Var classes() As String = Array("xojo-badge", "d-flex", "p-2", _ In our case, for SetBadge, we want to use this method signature instead: Extends control As WebUIControl, caption As String, indicator As String = "danger", top As Integer = -10, right As Integer = -10 ![]() “Extends” is the reserved keyword for this feature, for example: Extends myInstance As ExampleClassĪbove method would be extending an imaginary class called “ExampleClass”, and its instance would be available inside that method, accessible from the variable “myInstance”. The magic happens in the first parameter of this method. Then, in the inspector, ensure its visibility is set to Global, instead of Public or Protected. Now add a new method into that module, called “SetBadge”. The name of the module is up to you, I’ll be using WebExtensions in this example. Press on the Add button from the toolbar and select Module. Adding SetBadge and RemoveBadge methods to every visual control One option would be subclassing each control and adding new methods… but that’s so boring…Įxtension Methods are part of the Modules feature, allowing us to extend classes with methods, even if we don’t have access to their source code. This class can’t be modified, as it’s part of the framework. We know that every visual control inherits from WebUIControl. Let’s say we want to add a method to every visual web control. There are situations where you want to add functionality to a Xojo Framework class. But first, what’s an Extension Method anyway? I’ve ended up writing a few extension methods to use them on almost any WebUIControl. ![]() This doesn’t give a compile error but would require a significant amount of re-coding on all the controls I have (100’s of controls).I was having some fun with badges, trying to recreate a design. ![]() So I tested the alternative of: Redim objs(-1) Expected Object() but got Variant().” I suppose this is the compiler doing its thing again. ![]() eDueDate is a containterControl subclassīut now the compiler gives an error stating “Type mismatch error. where tbClosed is a canvas subclass and So instead I though I’d use an Object() array, thinking this would fix the problem as all the controls are subclasses of objects. I was previously using variant arrays and sometimes had problems when there was only one type of item in the array - the compiler would then seem to auto format as a array of the item’s type, rather than a variant array. I have a shared method into which I pass arrays of controls (mix of rectControls and containerControls) to effect alignment.
0 Comments
Read More
Leave a Reply. |